Python Basics
Python Basics
Python Programming
V2V AKSHAY GAIKWAD
PROFESSOR
CLASSES V2V CLASSES
Python Capsule
HISTORY OF PYTHON
FEATURES OF PYTHOBN
Python is a free and Python is free, there is no need to pay money for installing python and one can
easily download it from the website
open source language Python is an open source language, it makes the python popular
Python offers more effective an error checking than C. Python is having built in
Error checking and level data types for example dictionaries and flexible arrays.
high level data type If we compare python with AWK and Perl, Python has more general data types
and because of this python is applicable to bigger problem domain.
www.v2vclass.com Akshay A. Gaikwad
Features of Python programming
Python can run on any operating systems like Windows, Linux, Unix , DOS, etc . Python is
Platform Independent interpreted Language , it saves time as it does not need compilation and linking.
The interpreter can be utilized intelligently, which makes it easy to try different things with
Language elements of the language , to write disposed of programs , or to test function in the midst of
bottom up program development. It resembles a convenient work area calculator for clients
Python is having the features of abstraction and hiding of the details which
Python is User makes it more user friendly. In python we can divide the programs into
Friendly modules that can be used in other programs.
.python provides interface to the GUI kit such as TK
If you have good knowledge of C programming then it is easy to add new built in
Python is function or method or module to the interpreter.
If you are writing application in C and you are linking the python interpreter into
Extensible an application then you can use it is an extension or command language for that
application.
Python supports the object oriented programming concept. But OOP is optional
Python is object in python
oriented But whenever the user feels like using the OOPS concept user can use
12
www.v2vclass.com Akshay A. Gaikwad
Syntax means the structure of the program. If the syntax is not correct then it
result into syntax errors
SYNTAX ERRORS E.g:- (2+2) this wont give an error but (2+2 then it will give an error because
the parentheses is not closed hence it will give syntax errors.
Runtime errors are known as runtime errors because the error doesn’t
RUNTIME appear until after the program has started running runtime errors are
ERRORS also known exceptions which indicates something bad has happened
Runtime errors occurs very rarely
FEATURES OF PYTHOBN
FOLLOW US ON:
v2vclass
www.v2vclass.com
V2VClasses
Value is nothing but the numbers or letters. For e.g. 1,2,”hello”, 1.3222
These value belongs to different data types
In the above example 1 and 2 are integers
hello is a string data type
Any value written inside the quotation marks are considered as strings
While 1.3222 is a float data type
Variables are reserved memory location for storing the value, when we
create variable it reserves some spaces
Depending upon the data type interpreter reserves some memory and
decides what value can be stored in the allocated memory. We can
store integers, floats and strings in the variables
In python variable declaration is not required. Python determines the
types of variable i.e. integers,floats,etc.
FOLLOW US ON:
v2vclass
www.v2vclass.com
V2VClasses
ORDER OF OPERATIONS
EXPRESSIONS WITH
EXAMPLE
/ It divides the left hand operand by right hand operand and returns quotient
% It divides the left hand operand by right hand operand and returns remainder
// Floor Division – The division of operands where the result is the quotient in
which the digits after the decimal points are removed But if one of the
operands is negative , the result is floored , i.e., rounded away from zero
www.v2vclass.com Akshay A. Gaikwad
2. COMPARISON OPERATOR
Operator Description
== If the value of the operands are equal, then the condition becomes True
!= If value of the two operands are not equal, then the condition becomes True
<> If value of the two operands are not equal, then the condition becomes True
> If value of left hand operand is greater than right hand operator, then the
condition becomes True
< If value of right hand operand is greater than the left hand operand, then the
condition becomes True
>= If value of left hand operand is greater than or equal right hand operator, then
the condition becomes True
<= If value of right hand operand is greater than or equal to the left hand operand,
then the condition becomes True
www.v2vclass.com Akshay A. Gaikwad
3 ASSIGNMENT OPERATOR
Operator Description
= It is used to assign the value of right side operands to left side operand
+= It is used to add right operand to the left operand and result is assigned
to the left operand.
-+ The right operand gets subtracted from the left operand and the result is
assigned to the left operand
*= The right hand operand multiplied with left operand and tesult is assigned to left
operand
/= Left operand is divided by right operand and result is assigned to left operand
%= It performs modulus on tow operands and the result stored to left operand
**= It performs power calculation on operators and value is assigned to the left
operand
//= It performs floor division on operators and assigns value to the left operand
www.v2vclass.com Akshay A. Gaikwad
4 BITWISE OPERATOR
Operator Description
& It is Binary AND operator. This Operator is used to copy a bit to the result if it
exists in both operands
| It is Binary OR operator .it copies the bit if it is set in one operand but not both
^ It is Binary XOR operator .it copies the bit if it is set in one operand but not
both.
<< It is Binary Left Shift operator .it shifts the left operands value to left by the
number of bits given by the right operand.
>> It is Binary Right shift operator. It shifts the left operands value to right by the
number of bits given by the operand
www.v2vclass.com Akshay A. Gaikwad
5. LOGICAL OPERATOR
Operator Description
AND Logical AND– If both the operands are true then the condition becomes True
OR Logical OR:- If any of the two operands are non-zero then the condition becomes
True
NOT Logical NOT :- Used to reverse the logical state of its operand.
7. IDENTIFY OPERATOR
Operator Description
is Evaluate to true if the variables on either side of the operator point to the
same object and false otherwise
not is Evaluates too false if the variables on either side of the operators point to
the same object and true otherwise.
www.v2vclass.com Akshay A. Gaikwad
3.
ORDER OF OPERATIONS
▷ Parentheses have the highest precedence and Logical OR has lowest precedence
ORDER OF OPERATIONS
EXPRESSIONS WITH
EXAMPLE
FOLLOW US ON:
v2vclass
www.v2vclass.com
V2VClasses
INTERACTIVE MODE
SCRIPT MODE
INTERACTIVE MODE
SCRIPT MODE
FOLLOW US ON:
v2vclass
www.v2vclass.com
V2VClasses
If else statement
Nested if else
Elif ladder
www.v2vclass.com Akshay A. Gaikwad
1.
WHAT IS CONDITIONAL STATEMENTS
AND ITS TYPES IN PYTHON
IF
Consider the value is true, then the compiler
IF
CONDITION will first compile the conditional code
CONDITION
IS TRUE
IS FALSE Then it again execute the main function
CONDITIONAL Now if we consider the Boolean value is False
CODE then it will not execute the conditional code.
It will directly execute the main function after
the if-else block
STOP
For example:
we know that if an angle is 90⁰ then the triangle is right angle
Now we will see it in IF ELSE form
if(angle==90)
triangle is right angle
else
triangle is not right angle
NOTE:- If else loop is even possible without an else block
SYNTAX
If condition:
statement body1
else:
statement body2
if boolean_expression_1:
if nested_expression_1:
statement 1
else : NOTE: In nested if-else, we have to be careful with the indentation because multiple if-
statement 2 else constructs are involved in this process, so it becomes difficult to figure out
else: individual constructs. Proper indentation makes it easy to read the program.
if nested_expression_1:
statement 3
else:
statement 4
SYNTAX
First of all condition1 is tested and if it TRUE then statement1 will be
If condition1 :
executed and control comes out of the whole if-else ladder
statement1
If condition1 is FALSE then condition2 is tested.
elif condition2:
Control will keep on flowing downward, if none of the conditional
statement2
statement is TRUE.
elif condition3:
The last else is the default block of code which will gets executed if
statement3
none of the conditional statement is TRUE
else:
statement4
If else statement
Nested if else
Elif ladder
www.v2vclass.com Akshay A. Gaikwad
Prof. Akshay Gaikwad
FOLLOW US ON:
v2vclass
www.v2vclass.com
V2VClasses
While Loop
Nested Loops
Akshay A. Gaikwad82
www.v2vclass.com
2.
FOR LOOP IN PYTHON
SYNTAX
While condition:
statements
SYNTAX
Following is the syntax of a nested for loop :-
for iterating_var1 in sequence1:
for iterating_var2 in sequence2:
statement(s)
statement(s)
While Loop
Nested Loops
FOLLOW US ON:
v2vclass
www.v2vclass.com
V2VClasses