Indentation, structure, and how to execute Python code
Python is known for its readable, minimal syntax. Unlike many languages, Python uses indentation—not braces—to define code blocks. This makes code visually clean and consistent.
Indentation is not optional in Python. A typical block looks like this:
if True:
print("This is inside the block")
print("This is outside the block")
Most developers use 4 spaces per indentation level.
Use the # symbol for single-line comments:
# This is a comment
print("Hello") # Inline comment
Python does not require type declarations. Variables are created when assigned:
name = "Alice"
age = 30
is_active = True
You can run Python in interactive mode by typing:
python
Then try:
>> print("Hello from interactive mode!")
To run a Python file, create a file named script.py:
print("This is a Python script!")
Then run it from the terminal:
python script.py
Beginners often encounter:
Now that you understand Python’s syntax and how to run code, you’re ready to explore variables and data types in Lesson 3: Variables, Data Types, and Type Conversion.
← Back to Lesson Index