DAY TWO OF PYTHON NOTES BY ABHI TECH

 DAY 2 PYTHON NOTES


Day 2: Operators, Conditionals, and Loops ๐Ÿ‘ˆ


1️⃣ Operators in Python

➤ Arithmetic Operators

python
a = 10 b = 3 print(a + b) # Addition print(a - b) # Subtraction print(a * b) # Multiplication print(a / b) # Division (float) print(a // b) # Floor Division print(a % b) # Modulus print(a ** b) # Exponent

➤ Comparison Operators (returns True/False)

python
a = 5 b = 3 print(a > b) # Greater than print(a < b) # Less than print(a == b) # Equal to print(a != b) # Not equal print(a >= b) # Greater or equal print(a <= b) # Less or equal

➤ Logical Operators

python
x = 10 print(x > 5 and x < 20) # True print(x > 5 or x < 5) # True print(not(x > 5)) # False

2️⃣ Conditional Statements

if, elif, else

python
age = int(input("Enter your age: ")) if age >= 18: print("You are eligible to vote.") elif age > 0: print("You are underaged.") else: print("Invalid age.")

3️⃣ Loops in Python

while Loop

python
i = 1 while i <= 5: print("Hello", i) i += 1

for Loop (with range)

python
for i in range(1, 6): print("Number:", i)

➤ Loop with List

python
fruits = ["apple", "banana", "cherry"] for fruit in fruits: print(fruit)

break and continue

python
for i in range(1, 6): if i == 3: break print(i) for i in range(1, 6): if i == 3: continue print(i)
BY-ABHI TECH

Comments

Popular posts from this blog

DAY 3 OF PYTHON NOTES

DAY 4 OF PYTHON NOTES

DAY ONE OF PYTHON NOTES BY ABHI TECH