Chapter
Chapter
Index
1|Page
Python is a programing language developed by
Guido Van Rossum is very a very powerful language
which can be executed in two different modes
Intractive mode and Script mode .
Intractive mode:
In this mode python is executed line by line
and output of singe line will be displayed
Each line of code will be saved temporarily until
there is no error in the each lines of code, program
can only be entered if “>>>” is indicated in the
python prompt .(second line cannot be written
without executing the first line)
Eg1:
>>>print (“Python Programming Language”)
Python Programming Language
>>>x=10
>>>y=20
>>>z=x + y
>>>print (“The Sum”, z) The Sum = 30
Eg2:
>>> 5 + 10
15
2|Page
>>> 5 + 50 *10
505
>>> 5 ** 2
25
Script mode:
In this mode python is executed line by line
But the output will be showed only when Run
option is pressed or “F5” is pressed
Print Statement:
3|Page
It is a basic statement to display any output on the
screen
To display more than one value comma “,” can be
used to separate the values
Syntax:print(“Something”,”Something”)
Input Statement:
It is a basic statement to display get any input from
user at the run time
Syntax:Input(“Something”)
Eg:
>>h=input(“what is your name”)
what is you name
>>h=input()
4|Page
Indentation :
Python uses whitespace such as spaces and tabs to
define program blocks whereas other languages like
C, C++, java use curly braces { } to indicate
all statements within the block must be indented
with same amount spaces
Tokens Python :
breaks each logical line into a sequence of
elementary lexical components known as Tokens.
The normal token types are
1) Identifiers,
2) Keywords,
3) Operators,
4) Delimiters and
5) Literals.
Whitespace separation is necessary between
tokens, identifiers or keywords
Identifiers/Variables:
5|Page
An Identifier is a name used to identify a variable,
function, class, module or object.
Eg:Name,_jjjo,ww_2
Keywords :
Keywords are special words used by Python
interpreter to recognize the structure of program.
As these words have specific meaning for
interpreter, they cannot be used for any other
purpose.
6|Page
Operators:
In computer programming languages operators are
special symbols which represent computations,
conditional matching etc. The value of an operator
used is called operands. Operators are categorized
as Arithmetic, Relational, Logical, Assignment etc.
Value and variables when used with operator are
known as operands
Arithmetic operators:
An arithmetic operator is a mathematical operator
that takes two operands and performs a calculation
on them
Eg:
+ (Addition) >>> a + b 110
- (Subtraction) >>>a – b 90
* (Multiplication) >>> a*b 1000
/ (Divisioin) >>> a / b 10.0
% (Modulus) >>> a % 30
10 ** (Exponent) >>> a ** 2
10000 // (Floor Division) >>>
a//30 (Integer Division) 3
7|Page
Relational or Comparative operators :
A Relational operator is also called as Comparative
operator which checks the relationship between
two operands. If the relation is true, it returns True;
otherwise it returns False
Eg:
== (is Equal)
>>> a==b False
> (Greater than)
>>> a > b True
< (Less than)
>>> a < b False
>= (Greater than or Equal to)
>>> a
>= b True <= (Less than or Equal to)
>>> a
<= b False != (Not equal to)
>>> a != b True
Logical operators:
In python, Logical operators are used to perform
logical operations on the given relational
8|Page
expressions. There are three logical operators they
are and, or and not
Eg:
or >>> a>b or a==b True
and >>> a>b and a==b False
not >>> not a>b False i.e. Not True
Assignment operators:
In Python, = is a simple assignment operator to
assign values to variable. Let a = 5 and b = 10
assigns the value 5 to a and 10 to b these two
assignment statement can also be given as a,b=5,10
that assigns the value 5 and 10 on the right to the
variables a and b respectively. There are various
compound operators in Python like +=, -=, *=, /=,
%=, **= and //=
Conditional operator :
Ternary operator is also known as conditional
operator that evaluate something based on a
condition being true or false. It simply allows testing
a condition in a single line replacing the multiline if-
else making the code compact
9|Page
Delimiters:
Python uses the symbols and symbol combinations
as delimiters in expressions, lists, dictionaries and
strings. Following are the delimiters
Escape Sequences:
In Python strings, the backslash "\" is a special
character, also called the "escape" character. It is
used in representing certain whitespace characters:
"\t" is a tab, "\n" is a newline, and "\r" is a carriage
return. For example to print the message "It's
raining", the Python command is
>>> print ("It\'s rainning")
It's raining
11 | P a g e