1. Hello World!
Python's print() function outputs text. No semicolons needed - indentation defines code blocks.
print("Hello, World!")
print("Welcome to Python 🐍")
Hello, World!
Welcome to Python 🐍
2. Variables
Store data without type declarations. Use snake_case: lowercase_with_underscores.
first_name = "Alice"
last_name = "Smith"
age = 25
is_student = True
print(f"{first_name} {last_name} is {age} years old")
Alice Smith is 25 years old
Exercise: Create variables for your name, age, and city. Print a sentence about yourself.
3. Data Types
Python has 4 main types for beginners: int, float, str, bool. Use type() and isinstance().
| Type | Example | Check | Use Case |
|---|---|---|---|
| int | 42 | type(42) | Whole numbers |
| float | 3.14 | type(3.14) | Decimals |
| str | "Hello" | type("Hi") | Text |
| bool | True | isinstance(x, bool) | True/False |
num = 42
text = "Python"
print(type(num)) # <class 'int'>
print(type(text)) # <class 'str'>
4. Operators
Math, comparison, and logical operators work as expected.
a = 10
b = 3
print(a + b) # 13 (add)
print(a - b) # 7 (subtract)
print(a * b) # 30 (multiply)
print(a / b) # 3.333... (divide)
print(a // b) # 3 (floor divide)
print(a % b) # 1 (modulo)
print(a > b) # True
13
7
30
3.3333333333333335
3
1
True
5. String Operations
Strings support + (concat), * (repeat), and f-strings for formatting.
greeting = "Hello"
name = "Python"
print(greeting + " " + name) # Hello Python
print(greeting * 3) # HelloHelloHello
print(f"{greeting}, {name}!") # Hello, Python!
Hello Python
HelloHelloHello
Hello, Python!
6. Input/Output
input() always returns strings. Convert with int() or float().
name = input("Your name: ")
age = int(input("Your age: "))
print(f"Hi {name}, you are {age} years old!")
Your name: Alice
Your age: 25
Hi Alice, you are 25 years old!
🧠 Interactive Quiz (6 Questions)
Q1: What does type(42.5) return?
Q2: Fix: print("Age:", age)
Q3: What is 10 // 3?
Q4: Correct variable name?
Q5: What does input() return?
Q6: Output of "Hi" * 3?