Python unit 1
Python unit 1
Python supports three numeric data types: “integer”, “float”, and “complex”.
It is an *interpreted language*, meaning code is executed line by line, which differs
from compiled languages.
Python is *object-oriented* and *high-level*, allowing for easier interaction with
users.
It was created by Guido van Rossum during 1985 – 1990.
Features of Python –
Easy to Learn
Easy to read
Easy to maintain
Scalable
GUI Programming
Testthe
Start behaviour
application
Stop
Startthe
the application
application
Edit
Start theProgram
application
Relink the
Start theExecutable
application file
Testthe
Start Behaviour
application
Stopthe
Start application
application
Edit thethe
Start Program code
application
Python Syntax and Structure
Identifier –
a name give to variables, function, class, module or other entities in program.
Rules for naming –
Starting from (a-z), (A-Z), or Underscore(_)
The remaining letters can be letters, numbers, or underscore.
Case sensitive.
Cannot be reserved word – (have special meaning like false, true,
global and with etc.)
Operators in Python
Python includes various *operators* :
Arithmetic operators - perform common mathematical
operations.
a=4
b=2
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a%b)
print(a**b)
print(a//b)
Comparison operators - are used to compare two values.
a=4
b=2
print(a==b)
print(a!=b)
print(a>b)
print(a<b)
print(a>=b)
print(a<=b)
Logical operators - combine conditional statements.
a=2
print(a<5 and a<10) #output - true
a=5
print(a<1 and a<10) #output - false
5 -> 101
7 -> 111
a=5
b=7
print(a&b) #output – 5
print(a|b) #output - 7
Writing Python Programs