FUNDAMEN
TALS
PART -1
PRESENTED BY
NAVEEN KUMAR
VARSHNEY
PGT CS
OUTLINES
PYTHON CHARACTER SET
TOKENS
Subscribe my Youtube Channel – Naveen Varshney Official
PYTHON
CHARACTER SET
Character Set is a set of valid characters that a
Python language can recognize.
These are the following character set:
Letters A-Z , a-z
Digits 0-9
Space ! @ # $ % ^ & * ( ) _ - + = | \ : ; “ ‘
Special Symbols
<>,.?/
Blank space, tabs, carriage return,
Whitespaces
newline, formfeed
Other
ASCII and Unicode Characters.
Characters
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Python breaks each logical line into a sequence of
elementary lexical components known as tokens.
The smallest individual unit in a program is known as
a Token or Lexical unit.
Python has following Tokens :
Keyword
Identifiers (Names)
Literals
Operators
Punctuators
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Keyword
• Keywords are the reserved words in Python. We
cannot use a keyword as a variable name, function
name or any other identifier.
• Keywords are case sensitive.
• There are 33 keywords in Python 3.7 .
• All the keywords except True, False and None are in
lowercase.
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Keyword
• The list of all the keywords is given below :
False assert del for in or while
True break elif from is pass with
None class else global lambda raise yield
contin excep nonloca retur
and if
ue t l n
impor
as def finally not try
t
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Identifiers (Names)
• A Python identifier is a name used to identify a variable,
function, class, module or other object.
Rules for Identifiers :
Identifier must not be a keyword of Python.
Long sequence of letters and digits.
First character must be a letter or underscore( _ ).
Digits (0-9) can be part of the identifier except for the first
character.
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Identifiers (Names)
Rules for Identifiers :
Uppercase and Lowercase letters are different.
Identifiers are unlimited in length.
Identifiers cannot contain any special character except for
underscore ( _ ).
Examples of Valid Identifiers:
area , circle, mydata, MYDATA, _name, file7, nav_var
Examples of Invalid Identifiers:
nav@var , 12area , continue , My.data
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
• Literals are data items that have a fixed value.
• Python allows several kinds of literals:
1) String literals
2) Numeric literals
3) Boolean literals
4) Special literal None
5) Literal Collections
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
• A string literal is a sequence of characters surrounded by
quotes (single or double or triple quotes).
Ex- ‘nav’ , “xyz”
• Python allows some nongraphic-characters in String
values.
• Nongraphic characters are those characters that cannot be
typed directly from keyboard. Ex- backspace, tabs,
carriage return etc.
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
• These all nongraphic-characters can be represented by
using escape sequences.
• An Escape Sequence is represented by backslash ( \ )
followed by these one or more nongraphic characters.
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
• Some Escape Sequences are :
Escape Non-graphic Escape
Non-graphic character
Sequence character Sequence
\\ Backslash( \ ) \f ASCII Formfeed (FF)
\’ Single quote( ‘ ) \n Newline character
\” Double quote( “ ) \r Carriage Return (CR)
\a ASCII Bell(BEL) \t Horizontal Tab(TAB)
\b ASCII Backspace(BS)
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
String Types in Python :
Two String types :
1) Single-line Strings ( Basic Strings )
2) Multiline Strings
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
A. Single-line Strings ( Basic Strings ) :
String text is enclosed in single quotes (‘ ’) or double quotes
(“ ”)
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
A. Multiline Strings :
i. By adding a backslash at the end of normal
single-quote/double-quote strings. Add a backslash in the
end before pressing Enter to continue typing text on the
next line.
Ex- str=“Naveen\
Varshney”
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
A. Multiline Strings :
ii. By typing the text in Triple quotation marks, We can
write a multiline strings.
Ex- str=“ “ “ Naveen
Varshney” ” ”
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
Size of Strings:
• Size of a string as the count of characters in the
string.
• Escape Sequence is counted as a one character.
Ex- ‘\\’ Size is 1
‘abc’ Size is 3
‘Naveen\’s Car’ Size is 12
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
Size of Strings:
• For triple quoted multiline strings, EOL character is
counted as one character.
Ex- str=“ “ “My Size is 7
name” ” ”
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
Size of Strings:
• For Single/Double quoted multiline strings,
backslash( \ ) is not counted.
Ex- str=“ My\ Size is 6
name”
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
1) String Literals :
Size of Strings:
• To check the size of a string, we use len( ).
Ex- str=“ My\ Size is 6
name”
len(str)
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
2) Numeric Literals :
Two types :
1. Integer Literals
2. Floating Point Literals
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
2) Numeric Literals :
1. Integer Literals : Integer Literals are whole numbers
without any fractional part.
May be positive(+) or negative(-) sign.
Commas cannot appear in an integers constant.
Three types of Integer Literals:
i. Decimal Integer Literals
ii. Octal Integer Literals
iii. Hexadecimal Integer Literals
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
2) Numeric Literals :
i. Decimal Integer Literals : Sequence of digits (0-9).
Ex- 176, 23, -56, +86
ii. Octal Integer Literals : Sequence of digits (0-7) starting
with 0o (digit zero followed by letter o).
Ex- 0o10, 0o14
iii. Hexadecimal Integer Literals : Sequence of digits (0-9)
and letters (A-F) starting with 0x or 0X.
Ex- 0x4A6, 0XF28
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
2) Numeric Literals :
2. Floating Point Literals : also called real literals. Real
numbers are the numbers having fractional parts.
Two types:
i. Fractional Form
ii. Exponent Form
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
2) Numeric Literals :
i. Fractional Form : signed or unsigned digits including
decimal point between digits.
Some Valid real literals in fractional form: 2.5, -18.54,-0.0059,
.7(0.7), 2. (2.0) .
Some Invalid real literals : 5, 12/4, 2345.26.9, 47,234.50
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
2) Numeric Literals :
ii. Exponent Form : consists two parts : mantissa and
exponent.
Ex- 9.5 can be written in exponent form is:
0.95x101 = 0.95E01
Some Invalid Exponent form : 2.3E , 0.54E1.7 , 12,34E07
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
3) Boolean Literals :
Two Boolean Values :
1. True : Boolean true
2. False : Boolean false
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
4) Special Literal None :
None literal is used to indicate absence of value.
Ex- a=None
print(a)
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Literals/Values
5) Literal Collections :
• Literal collections are 4 types:
1. List
2. Tuple
3. Dictionary
4. Set
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Operators
• Operators are tokens that trigger some
computation or action when applied to
variables.
• Types of Operators :
a) Unary Operators
b) Binary Operators
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Operators
a) Unary Operators : required only one operand.
Some unary Operators:
+ Unary plus
- Unary minus
~ Bitwise complement
not logical negation
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Operators
b) Binary Operators : required two operand.
Types of Binary Operators :
1. Arithmetic operators
2. Bitwise operators
3. Shift operators
4. Identify operators
5. Relational operators
6. Logical operators
7. Assignment operators
8. Membership operators
Subscribe my Youtube Channel – Naveen Varshney Official
TOKENS
Punctuators
• Punctuators are symbols that are used
in programming languages to organize
sentence structures.
• Most common punctuators are:
(){}[];,.\#@:=‘“
Subscribe my Youtube Channel – Naveen Varshney Official