Lesson 4 / 49

Python Syntax

Understand Python syntax: indentation-based blocks, one statement per line, comments and case-sensitive names.

Indentation is structure

Use 4 spaces per level. Mixing tabs and spaces is an error.

def greet(name):
    if name:
        print(f"Hi, {name}")
    else:
        print("Hi, stranger")

Statements & comments

One statement per line, no semicolon. # starts a comment. Names are case-sensitive.