Chapter 2: Python Basics – Syntax, Variables & Data Types

1. Basic Python Syntax

Python is easy to read because it avoids complex symbols. Key rules:

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:

Example:

name = "Alice"
age = 25
height = 5.9
is_student = True

print(name)        # Output: Alice
print(age + 5)     # Output: 30

Exercise 1:

  1. Create a variable country with your country's name
  2. Create population (number) and is_developed (True/False)
  3. 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