Back to Python Course
Python Course
I. Conditional Statements (if, elif, else)
Used to control the flow of execution based on conditions.
Syntax:
if condition: # code block elif another_condition: # another block else: # default block
Example:
age = 20 if age >= 18: print("You are an adult.") elif age > 13: print("You are a teenager.") else: print("You are a child.")
II. Loops
- For Loop
Used to iterate over a sequence like a list, tuple, dictionary, or string.
names = ["Praveen", "Anusha", "Kasyap", "Keerthana"] for name in names: print(name)
- While Loop
Repeats as long as the condition is True.
count = 0 while count < 5: print(count) count += 1
break and continue:
break: Exit the loop earlycontinue: Skip the rest of the loop for the current iteration
for i in range(10): if i == 5: break if i % 2 == 0: continue print(i)