Unit7 Read Me
Unit7 Read Me
Learning objectives
Features of Python
Writing and executing commands in Python
How to exit the Python Shell
Operators in Python
Variation in Python
Using the input() function for user input
Conditional constructs
Snap Recap
What is Python?
A high-level programming language which is open source and object-oriented. (OOP- Object-
oriented program)
Python owner
Python Software Foundation (PSF)
Usage of Python
To create web-based applications
To handle large amounts of data
To perform complex calculations
To connect database systems and to read and modify files
Features of Python
Python source code is freely available.
It is a loosely typed object-oriented programming language with few keywords and simple
English-like structure, and therefore easy to learn.
It supports Graphical User Interface (GUI).
Operators in Python
Arithmetic operators
Assignment operators
Operator Syntax Description Example
= Num=5 Assigning >>>Num=5
+= Num+=5 Increase the value of Num=17>>>
OR Num by 5 Num+=5
Num=Num+5 22
-= Num-=5 Decrease the value of Num=20
OR Num by 5 >>>Num-=5
Num=Num-5 15
*= Num*=5 Multiplies the value of Num=20
OR Num by 5 >>>Num*=5
Num=Num*5 100
/= Num/=5 Divides the value of Num=100
OR Num by 5 >>>Num/=5
Num=Num/5 20
%= Num%=5 Displays the remainder Num=25
OR by dividing the value of >>>Num%3
Num=Num%5 Num by 5 1
//= Num//=5 Variable Num is Num=35
OR assigned floor value of >>>Num//3
Num=Num//5 division of Num by 5 11
**= Num**=5 Num is assigned a Num=10
OR value of last value of >>>Num**=2
Num=Num**5 Num raised to the 100
power of 5
Relational operators
Logical operators
Variable in Python
Variable: named memory locations whose value may chance during the execution of the program. Rules
for naming:
Declaring variables
- Example: x = 5
Assign multiple values to multiple variables
x= y= z= 25
Syntax: input(<Prompt>)
Conditional constructs
- If statement
- If- else statement
- If- elif ladder
If statement
The if statement checks if the condition given after if is true, then the statement (s) following
the if condition is/ are executed. If condition is false, then the flow of control is transferred to
the next un-indented statement (s).
Syntax: if <condition>:
Statement (s)
If-else statement
Syntax: if <condition>:
Statement (s)
else:
Statement (s)
If-elif statement
Syntax:
If <condition>:
Statement (s)
Elif<condition>:
Statement (s)
Elif<condition>:
Statement (s)
Else:
Statement (s)