SNV GLOBAL SCHOOL
COMPUTER SCIENCE (083)
PYTHON FUNDAMENTALS – PART 1
Name:………………….... Class:XI
A Python program refers to a set of instructions that processes the input to display output.
• Python Character Set
Character set is a set of valid characters that a language can recognize. A character represents
any letter, digit or any other symbol. Python supports Unicode encoding standard. It includes,
✓ Letters : A-Z, a-z
✓ Digits:0-9
✓ Special symbols:/,( )..
✓ Whitespaces such as space, back space, tab..
• Tokens
The smallest individual unit in a program is known as Token or lexical unit.
Tokens
Keywords Identifier Literals Punctuators Operators
/Constants
String Boolean Numeric Special Literal
Literal collections
Single line String True Decimal None
Integer Octal
Multi line String False
Hexadecimal
Functional
Floating point Exponent
Complex Numbers
It includes:
• Keywords
A keyword is a reserved word with special fixed meaning in a programming language.
It must not be used as normal identifier names.
Eg:
for, break, continue etc.,
• Identifier
Identifiers are fundamental building blocks of a program, and can be referred to the names
1
given to the different parts of the program, for eg., variable, object, function etc.,
Some of the naming conventions to be followed in naming an Identifier includes,
❖ An identifier is an arbitrarily long sequence of letters and digits, unlimited in
length.
❖ Upper- and lower-case letters are different as Python is case sensitive.
❖ An identifier cannot contain any special character except for underscore(_).
❖ The digits 0 through 9 can be part of the identifier except for the first character.
❖ The first character must be a letter, or the underscore(_) that counts as a letter.
Eg:
_ds, pp9
• Literals
Literals often referred to as constant values are data items that have a fixed value. Python
allows several kinds of literals:
❖ String
A string literal is a sequence of characters, on which mathematical operation
cannot be performed and is enclosed in single quote or double quotation.
String types in Python:
▪ Single line string:
A Single line string is a string enclosed within single quote or double
quotation and gets terminated in one line.
Eg:
A=’ISM’
▪ Multiline string:
Multi line string is a string that spreads across multiple lines as one single
string.
Multiline strings can be created in two ways:
a. By adding back slash at the end of normal single quote/double
quote strings:
In normal strings,‘\’ backslash symbol is added at the end of the
line before pressing enter to continue typing text in the next line.
Eg:
A=’Indian\
School\
Muscat’
b. By typing the text in triple quotation marks:
Python allows Multi line strings by enclosing them in triple single
/double quotation marks. In the given case, backslash symbol is
not added at the end of the line.
Eg:
A=’’’Indian
School
Muscat’’’
❖ Numeric:
Numeric literals store numeric values in Python on which
mathematical operations can be performed.
It can be classified into
▪ Integer literals:
Integer literals are whole numbers with no decimal point(fractional part).
Integers can contain (+) or (-) sign, indicating positive or negative value.
Commas cannot appear in an integer constant .
2
Eg:
1234,-7
Decimal Integer Literal – An integer literal consisting of sequence of digits
is called Decimal Integer Literal. It does not begin with 0.
Eg: -56,34
Octal Integer Literal –
❖ A sequence of digits starting with 0o or 0O(Zero O).
❖ Octal value contains only digits 0-7 and are written to the base 8.
Eg: 8 can be written as 0O10
Hexadecimal Integer Literal –
❖ A sequence of digits starting with 0x or OX(Zero X).
❖ Hexadecimal value contains only digits 0-9 and letters A to F only,
and are written to the base 16.
Eg: 15 can be written as 0xF
▪ Floating point literals:
Floating literals are also called real literals. They are numbers with
decimal points. They can be written in 2 forms.
Functional form- A real literal in functional form consists of
signed or unsigned digits with decimal point between digits.
Eg: -5.87
Exponent form – A real literal in exponent form consists of
two parts-mantissa and exponent.
Eg: For instance, 5.8 can be written as 0.58x101 =0.58E01,
where mantissa part is 0.58 and exponent part is 1.
▪ Complex numbers:
In Python Complex numbers are represented in the form of A+Bj, where
A indicates the real part and B indicates the imaginary part and j =√−1..
The real and imaginary part, both are represented as floating point
numbers. The complex numbers with non zero real part is displayed with
parenthesis around it. The complex number with zero real part is
displayed without parenthesis.
Eg:
3
✓ Boolean literal:
Boolean Literal in Python indicates one of the two values True(Boolean True) or False(Boolean False).
Eg:
A=True
✓ Special literal None:
The special literal None in Python indicates absence of value. Or unidentified value.
Eg: A=None
print(A)
Output:None
✓ Literal collections
It includes Tuples, Lists, Dictionary and Sets.
Eg:[1,2,3]
• Operators
The operator can be defined as a symbol associated with a particular operation, and the data on
which the operation is being applied is called operands.
Eg: 5+7 (Expression-combination of operands and operators)
operand - 5,7
operator - +
• Punctuators:
Punctuators are symbols that are used in programming languages to organize sentence structures, and
indicate the rhythm and emphasis of expressions, statements and program
Some common punctuators of Python Programming Language, ‘, ( ), [ ], { }. Punctuators are also
called Delimiters.