Python Fundamentals
Python Fundamentals
Python character set: Character set is a set of valid Characters that a language can
recognize.
TOKENS IN PYTHON
The smallest individual unit in a program is known as Token.
Keywords:
Examples: True, False, None, for, while, if, else, or, elif, break, is, in, with, import
etc.
Identifiers (Names):
Naming rules:
_name=”anuj” s.name=”anuj”
Literals:
String Literals
Numeric Literals
Boolean Literals
Special Literal None
String Literals:
A string literal is a sequence of characters surrounded by quotes.
Nongraphic character:
Nongraphic characters are those characters that cannot be typed directly from
keyboard.
\\ - Backslash (\)
\’ -Single quote (‘)
\t - Horizontal tab
String type in Python
Numeric Literals
Integer
Floating point
Complex numbers
Integer: Integer Literals are whole number without any fractional part. It may
contain either + or – sign. A number with no sign is assumed to be positive.
Exponent form:
A real literal in Exponent form consists of two parts: mantissa and exponent
Example: 7.5=0.75x101=0.75E01,
Complex numbers: python represents complex numbers in the form A+Bj, python
uses j or J in place of traditional i.
X=0+5.5j Y=2.3+5j
x.imag=5.5 y.imag=5.0
Examples:
>>> 5 and 6 >>> 5 or 6 >>> 5 or 6 and 0 >>> not 5
6 5 5 False
>>> 0 and 5 >>> 0 and 5 >>> 0 and 5 or 2 >>> not (0 and 2 or 0)
0 5 2 True
Truth value (False): 0, 0.0, 0j, False, None, ‘’, *+, ,-, ()
Punctuators:
Punctuators are symbols that used in programming languages to organize sentence
structure, statement, program structure etc.
Examples:
# \( )*+ ,-: = ‘“