Variables & Data Types
Python supports various data types like int, float, string, and boolean.
name = "John"
age = 25
is_active = True
height = 5.9
Task: Declare a variable
score and assign a
value of 100.
Conditional Statements
Use if, elif, and
else to control flow.
score = 85
if score >= 90:
print("Excellent!")
elif score >= 75:
print("Good Job!")
else:
print("Keep Trying!")
Task: Add a condition for
score < 50 that
prints "Needs Improvement".
Loops
Loops help in iterating over sequences or running code multiple times.
for i in range(5):
print("Iteration:", i)
Task: Create a loop that prints numbers from 1 to 10.
Functions
Functions allow code reuse and better organization.
def greet(name):
print("Hello, " + name + "!")
greet("Alice")
Task: Write a function that takes two numbers and returns
their sum.
Lists
Lists store multiple values in a single variable.
fruits = ["apple", "banana", "cherry"]
print(fruits[0])
Task: Add "mango" to the above list.
Dictionaries
Dictionaries store data in key-value pairs.
student = {"name": "John", "age": 20}
print(student["name"])
Task: Add a key "grade" with value "A" to the dictionary.
List Comprehensions
A concise way to create lists.
squares = [x**2 for x in range(5)]
print(squares)
Task: Create a list comprehension to store even numbers from
1 to 10.