Prepared By: Y. Rohita Assistant Professor Dept. of IT
Prepared By: Y. Rohita Assistant Professor Dept. of IT
Y. Rohita
Assistant Professor
Dept. of IT
Syllabus
Reference books:
1. Introduction to Computation and Programming using Python,
Revised and Expanded Edition, John V. Guttag, The MIT Press.
2. Programming Python, Fourth Edition by Mark Lutz, O'Relly
3. Python Programming using problem solving approach, Reema
Thareja, Oxford Higher Education.
UNIT – I
Contents:
Introduction to Python
History
Features
Setting up path
Working with Python Basic Syntax
Variable and Data Types
Operators
Conditional Statements(If ,If- else ,Nested if-else)
Looping( for, While Nested loops)
Control Statements(Break , Continue ,Pass)
Introduction to Python
Python is a high-level, interpreted, interactive and object-oriented
scripting language. It is designed to be highly readable.
8. Click Run.
9. A Python 3.7.0 (32-bit) Setup pop-up window will appear.
10. Ensure that the Install launcher for all users (recommended) and
the Add Python 3.7 to PATH checkboxes at the bottom are checked.
Multi-line statement:
bin()
oct()
hexa()
Examples:
Complex data type examples:
bool data type examples:
Python provides some inbuilt functions :
1. print(): print the statement
ex: print(“hello”)
2. type( ):
It is used to identity the type of the object
Ex: a=10
print(“Type of a:”,type(a))
b=“Hello”
print(“Type of b:”, type(b))
c=[ ]
print(“Type of c:”,type(c))
1. Arithmetic operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Bitwise Operators
6. Membership Operators
7. Identity Operators
Arithmetic operators:
Arithmetic operators are used to perform mathematical operations
like addition, subtraction, multiplication etc.
Arithmetic operators in python
Operator Meaning Example
Print(‘not x is ‘,not x)
Assignment operators:
Y=4 0
Print(x&y) 4
Print(x|y) -11
Print(x~y) 14
Print(x^y) 2
Print(x>>y) 40
Print(x<<y)
Special operators:
Python language offers some special type of operators like
1.membership operator.
2. identity operators
Membership operators:
in and not in are the membership operators in Python.
They are used to test whether a value or variable is found in a
sequence(string, list, tuple, set and dictionary).
Block:
1. if:
Condition returns true then it executes the if block otherwise if block
execution is skipped.
output 1: output 2:
enter a positive number5 enter a positive number5
Given number is 1 digit number Given number is >=2 digit number
end end
3.elif:
While:
In python, while loop is used to execute a block of statements
repeatedly until a given a condition is satisfied.
when the condition becomes false, the line immediately after the
loop in program is executed.
for loop executes the given logic with respect to every element of the
iterable object
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for x in numbers:
print (x)
Control Statements(break , continue ,pass)
break :
To interrupt the loop, to start a new iteration (one “round” of
executing the block), or to simply end the loop we use break.
EX:
print (“begin”)
i =1
while True:
print (“welcome”)
i =i+1
if i==5:
break
else:
print (“if else”)
print (“end”)
Continue:
It causes the current iteration to end, and to “jump” to the
beginning of the next.
It basically means “skip the rest of the loop body, but don’t end
the loop.”
EX
while True:
name = input("enter user name:")
if name!='Hema':
continue
password = input("Hello, Hema enter password")
if password=='hema':
break
print("access granted")
break
Pass: