Professional Documents
Culture Documents
Installing Python:-
For installing Python, we must first download the installation package of requried version from
the link/URL.
Https://www.python.org/downloads/
Python is used by Google Search engine, Youtube etc. It is widely used for system programming,
GUI Programming, Internet Scripting/Web, gaming, text processing, network programming,
commercial robots and in space & scientific applications.
To write & run python programs interactively we can either use command line window or IDLE
(Integrated Development Learning Environment). IDLE is a program that allows the user to edit,
run, browse and debug a python program from a single interface.
Python Shell:- When we start Python IDLE, it always starts up in the shell- Python shell is an
interactive window where you can type the python code to see the output in same window. The
interactive interpreter of python is termed as python shell
Python IDLE comprises Python Shell (Interactive mode) and python Editor(script mode). The
three greater than signs(>>>) are called the prompt or python command prompt.
Python Editor Window (Working in Script Mode):- Python Script mode or Python Editor is a
standard text editor where you can type or edit the code. The files are saved by .py extension
automatically.
Exiting Python:- In order to exit the Python Command prompt, click Ctrl+Z and press Enter, or
type quit() or exit() & press enter key.
Variable:- A name given to a memory location where a user can store or access any value. In a
variable, a value can be changed during the execution of a program. Every variable has a type
and this type defines the format and behaviour of the variable. e.g x=5
means x is a variable and it contains a value 5. Actually here x is the name of memory location
which holds value 5.
Note:- In python, every element is termed as an object. Hence, a variable is also an object in
python.
Identity of variable/object.
Type of variable/object.
Value of variable/object.
Identity of Variable:- It refers to the objects address in memory which does not change once
it is created. The address of an object can be checked using function 'id'.
Syntax: id(object)
e.g id(x) will display something like
12406923-> Address of memory location of x
Type of variable/object:- It refers to the value it contains and the type of allowable operations on
these values. It can be checked by 'Type' function.
Syntax:- Type(variable or object)
e.g x=5
There should be one & only one variable on the left-hand side of the assignment operator. This
variable is called Left value or L-value. There can be any valid expression on the right-hand side
of assignment operator. It is called Right-value or R-value.
Number:- It stores numerical values. Python supports three in-build numeric data types.
Integer (int) :- It represents whole number without any fractional part. They can be -ve or +ve
number which have unlimited size in Python. e.g 2,-67,239,-67493 etc.
Note:- Range in python can be from -2147483648 to 2147483647 and long integer has unlimited
range subject to available memory.
Floating point (float):- It denotes numbers with fractional part i.e which contains a decimal
point. e.g 3.5, -4.57, 6.0, 1893.56 etc.
Complex numbers:- These are made up of pairs of real and imaginary numbers. They are of
the form x+yj or x-yj.
Note:- Complex numbers are not extensively used in python programming.
Boolean (bool):- It represents one of the two possible values, True or False. Any expression
which can be True or False has the data type bool. e.g 5<10 will give True.
Variable Names:- There are certain rules which are to be followed for a valid variable name.
i. Arithmetic operators
i. Unary
ii. Binary
Unary operators:- Operator which requires only one operand to be operated upon. e.g ( - , +, !)
Like -2, +3 , ! True etc.
Binary Operators:- Operator which requires two operands to be operated upon e.g (+ , - , * , / , //
, % , **)
Usage of some operators :
/ - Division e.g 5/2 = 2.5
// - Integer Division e.g 5//2 = 2
% - Remainder or modulus e.g 5%2 = 1
Relational operators:- Operators used for comparing two expressions and results in either True or
False.
e.g < , > , <= , >= , == , !=
Logical operators:- Logical operators are used to connect two relational expressions, resulting in
True or False. e.g and , or , not(unary).
‘and’ operator results in true if both the operands are true.
‘or’ operator results in true if any of the operands is true.
‘not’ operator results in true if the operand is false & vice-versa.
Precedence of operators:- Precedence means priority of execution of operators in an expression
-,+,!
* , / , // , % , **
and
or
i. Identifiers
ii. Keywords
iii. Literals
iv. Operators
v. Delimiters
Identifiers:- The name of any variable, constant, function or module is called an identifier.
e.g x , xyz , a12 etc.
Keywords:- The reserved words of python which have a special meaning for the interpreter.
e.g print , if , for etc.
Literal: A fixed numeric or non-numeric value is called a literal. e.g 2, 'abc' , 2.43 etc.
Delimiters:- Symbols which can be used as separator of values or to enclose some values.
e.g () , {} , ',’ , : etc.
Comments:- Comments are statements in a script that are ignored by the python interpreter and,
therefore have no effect on the actual output of code. It makes the code more readable &
understandable.
Comment starts with '#' anywhere in a line.