Python programming
language
DIT 1st
Semester
By : Azaz
Tahir
Python Basics: Variables Python Basics: Data Types
Variables store data in Python
Common Data Types in Python:
Example:
• Integer (int) (0123456789)
AGE = “28” • Float (float) (3.17, 2.8 etc)
Percentage = “73.79”; • String (str) (Paksitan, Apple)
Name= “AZAZ TAHIR”; • Boolean (bool) (True, False)
inputtype = “true”
Operators in Python
1 Arithmetic
Operators 4 Logical
Operators
2 Assignment
Operators 5 Bitwise
Operators
3 Comparison
Operators 6
Membership
Operators
7 Membership
Operators
1. Arithmetic
Operators
An Arithmetic Operator is a mathematical function that performs a
calculation on two operands. The different types of arithmetic operators
include addition, subtraction, multiplication, division, modulus,
exponentiation and floor division.
• Addition (+) print(x + y) # 13
suppose print(x - y) # 7
• Subtraction (-) x = 10 y print(x * y) #30
• Multiplication (*) =3 print(x / y) # 3.33
• Division (/) print(x % y) # 1
• Modulus (%) print(x ** y) #1000
• Exponentiation print(x // y) # 3
(**)
• Floor division (//)
2. Comparison
Operators
Comparison operators in Python, also called relational operators,
are used to compare two operands. They return a Boolean True or False
depending on whether the comparison condition is true or false.
If (x > y)
• Equal (==) Print (x)
suppose Else { the value is less then
• Not equal (!=) y}
x = 10 y
Conditio
• Greater than (>) =3 ns
If (x != y)
• Less than (<)
Print (x)
Else { the value is not
• Greater than or equal to
equal to Y}
(>=)
• Less than or equal to
(<=)
3. Logical
Operators
The Python ternary operator (or conditional operator), tests if a
condition is true or false and, depending on the outcome, returns the
corresponding value
Used to combine conditional Print (x > y AND y < x)
statements: True
suppose
x = 10 y
• AND (and)
• OR (or) =3
• NOT (not)
Print (x > y OR y < x)
True
2. Membership
Operators
We use membership operators in Python to check whether a sequence is
present in the object or not.
Check for membership in sequences
like strings, lists, or tuples:
• In (in)
• Not in (not in) Example
s
fruits = ["apple", "banana", "cherry"]
print("banana" in fruits) # True
print("orange" not in fruits) # True
Thank
You