x = 10 # Assignment statement print("Hello") # Function call statement if x > 5: # Conditional statement print("x is greater than 5")
=
name = "Raj" # Assign a string to a variable age = 25 # Assign an integer to a variable is_student = True # Assign a Boolean value
a, b, c = 1, 2, 3 # Assign multiple values at once x = y = z = 10 # Assign the same value to multiple variables
10 + 20 # Arithmetic expression (but not useful as a standalone statement) print("Hello, Ram!") # Function call statement
if
elif
else
age = 20 if age >= 18: print("Ram is eligible to vote.") elif age >= 16: print("Ram can get a learner's license.") else: print("Ram is too young.")
for
while
names = ["Raj", "Ram", "Anand", "Bala"] for name in names: print(f"Hello, {name}!")
count = 0 while count < 5: print(f"Count: {count}") count += 1
def
def greet(name): print(f"Hello, {name}!") greet("Karthik") # Function call statement
import
import math # Import the entire math module from datetime import date # Import only the date class from datetime
break
continue
pass
for i in range(10): if i == 5: break # Exit the loop when i is 5 print(i)
for i in range(10): if i % 2 == 0: continue # Skip even numbers print(i)
if x > 10: pass # Placeholder for future code
return
def add(a, b): return a + b result = add(5, 10) # result = 15
try
except
finally
try: result = 10 / 0 except ZeroDivisionError: print("Cannot divide by zero!") finally: print("Execution complete.")
if x > 10: print("x is greater than 10") # Block of code under if print("This is part of the if block")
x = 10 print("Hello")
if x > 10: print("x is greater than 10") print("This is a compound statement")
name = "Suresh" age = 28
if age >= 18: print(f"{name} is eligible to vote.") else: print(f"{name} is not eligible to vote.")
names = ["Sujatha", "Kavitha", "Sathish"] for name in names: print(f"Hello, {name}!")
def greet_person(name): print(f"Good morning, {name}!") greet_person("Ramesh")