1. Basic Python Syntax
Python is easy to read because it avoids complex symbols. Key rules:
- ✅ Indentation matters (use spaces/tabs for blocks)
- ✅ No semicolons (
;) needed - ✅ Comments start with
#
Example:
# This is a comment
print("Hello") # This prints Hello
if 5 > 2:
print("Five is greater than two!") # Indented block
Common Error:
if 5 > 2:
print("Error!") # Missing indentation → ERROR!
2. Variables – Storing Data
Variables store data (like containers).
Rules for Naming Variables:
- Must start with a letter or
_ - Cannot start with a number (
1var❌) - Case-sensitive (
Age≠age)
Example:
name = "Alice"
age = 25
height = 5.9
is_student = True
print(name) # Output: Alice
print(age + 5) # Output: 30
Exercise 1:
- Create a variable
countrywith your country's name - Create
population(number) andis_developed(True/False) - Print all three variables
country = "Canada"
population = 38000000
is_developed = True
print(country, population, is_developed)
Chapter Summary
Variables
Store data (x = 10)
Data Types
int, float, str, bool
Type Conversion
str(10) → "10"
User Input
input() always returns string