4.2.Python_Fundamentals
4.2.Python_Fundamentals
Python Fundamentals
Python Character Set
Tokens
Keywords
Identifiers
Literals / Values
Operators
Types of Operators
Python Fundamentals
In order to provide an input, process it and to receive output, we need to write a program.
Program, is a group of instructions which controls processing. In other words, base for
processing is ‘the Program’. In this chapter we will come to know about various element of
processing like – character set, token, expressions, statements, input.
Character set includes letter, sign, number, symbol. Letters: A-Z, a-z Digits: 0-9
Special Symbols: _, +, -, *, /, (, ), {, } … Etc. White Spaces: blank space, tab, carriage return,
newline, formfeed etc. Other characters: Python can process all characters of ASCII and
UNICODE.
Tokens
Token- is the smallest unit of any programming language. It is also known as Lexical Unit.
Keywords
These are reserved for specific functioning. These can not be used as identifiers, variable name
or any other purpose. Available keywords in Python are :-
Identifiers
These are building blocks of a program and are used to give names to different parts/blocks of a
program like - variable, objects, classes, functions.
An identifier may be a combination of letters and numbers. An identifier must begin with an
alphabet or an underscore( _ ). Subsequent letters may be numbers(0-9). Python is case
sensitive. Uppercase characters are distinct from lowercase characters (P and p are different for
interpreter). Length of an Identifier is unlimited. Keywords can not be used as an identifier.
Space and special symbols are not permitted in an identifier name except an underscore( _ )
sign. Some valid identifiers are – – Myfile, Date9_7_17, Z2T0Z9, _DS, _CHK FILE13. Some invald
identifiers are – – DATA-REC, 29COLOR, break, My.File.
Literals / Values
String literals :- “Pankaj” Numeric literals :– 10, 13.5, 3+5i Boolean literals :– True or False
Special Literal None :– Literal collections.
1. String Literals
String Literal is a sequence of characters that can be a combination of letters, numbers and
special symbols, enclosed in quotation marks, single, double or triple(“ “ or ‘ ‘ or “’ ‘”). In
python, string is of 2 types-
Single line string :- Text = “Hello World” or Text = ‘Hello World’ Multi line string :- Text =
‘hello\world’ or
2. Numeric Literals
int (signed integers) Decimal Integer Literals :– 10, 17, 210 etc. Octal Integer Literals :- 0o17,
0o217 etc. Hexadecimal Integer Literals :– 0x14, 0x2A4, 0xABD etc.
2. float ( floating point real value) Fractional Form :– 2.0, 17.5 -13.5, -.00015 etc. Exponent
Form : -1.7E+8, .25E-4 etc.
3+5i etc.
3. Boolean Literals
A= True B= False
4. Special Literals
X = None
Operators
An Operator is a symbol that trigger some action when applied to identifier (s)/ operand (s) .
Therefore, an operator requires operand (s) to compute upon. example : c = a + b
Here, a, b, c are operands and operators are = and + which are performing differently.
Types of Operators
1. Unary Operator
2. Binary Operator
Assigment Operator (=, /=, +=, -=, *=, %=, **=, //=)
Punctuators
In Python, punctuators are used to construct the program and to make balance between
instructions and statements.
Punctuators have their own syntactic and semantic significance. Python has following
Punctuators - ‘ , ” , #, , (, ), [, ], {, }, @. ,, :, .. `, =