Python Fundamental
Python Fundamental
Python
FUNDAMENTALS
3.1 OUTLINE
1. Introduction
2. Python Character Set
3. Tokens
4. Barebones of a Python Program
5. Variables and Assignments
6. Simple Input and Output
3.2 P y t h o n C h a r a c t e r
set
Character set is a set of valid characters that a language can
recognize.
Python has the following character set :
□ LETTERS : A-Z , a-z
□ DIGITS : 0-9
□ Special Symbols: space + - * / () {} [] etc.
□ Whitespaces : Blank space, tabs, newline etc.
□ Other character : Python can process all ASCII and
Unicode character as part of data or literal
3.3 T o k e n s
The smallest individual unit in a program is known as a TOKEN
or LEXICAL unit.
Python has following tokens:-
1. Keywords
2. Identifiers(Names)
3. Literals
4. Operators
5. Punctuators
Let us talk about these one by one
3.3.1 K e y w o r d s
A keyword is a word having special meaning reserved by
programming language.
Examples:
•False
•Break
•If
•Elif
•While
•lambda
3.3.2 I d e n t i f i e r s
(Names)
Identifiers are fundamental building blocks of a program and are
used as the general terminology for the names given to different
parts.
Identifiers forming rules are:-
• The first character must be a letter ;underscore counted
• Upper and Lower case letters are treated differently
• Digits can be a part of identifiers 0-9 , but not in the first place
• Identifiers are unlimited in length
• An Identifier must not be a keyword
• An identifier cannot contain any special character except underscore
Examples
Valid:-
•Myfile
•Data9_987_0
•_CHK
Invalids:-
•DATA-REC
•29CLCT
•break
•My.file
3.3.3 L i t e r a l s / V a l u e s
3.3.3D S p e c i a l L i t e r a l
N
Theo
Non
ne ve
alue in python means “There is no useful
information ” or “ There is nothing here”
3.3.4 O P E R A T O R S
Operators are tokens that trigger some computation /
action when applied to variables and objects in an
expression .
□ Bitwise OR |
□ Bitwise exclusive OR ^
Identity operators
Age 16
h a n d l i n g of
variables
Memory has literals/values at defined memory
locations , and each memory location has a memory
address.
You have given statement age=15 , variable age will be
created as a label pointing to memory location where
value 15 is stored.
And when you give statement age = 20 , then …..
Variables
14 15 16 17
20200 20216 20232 20248
Variables
14 15 16 17
20200 20216 20232 20248
14 15 16 17
20200 20216 20232 20248
x Int : 10
x Int : 10