Module 1: Python IntroductionBeginner15 min read
Python Syntax & Indentation
Master Python's whitespace rules, statements, and block structures.
Key Takeaways & Core Concepts
- to indicate a block of code.
- per indentation level (avoid mixing tabs and spaces).
Python Syntax & Indentation
### Python Syntax & Indentation
Unlike other languages that use curly brackets {} to define blocks of code, Python uses indentation (whitespace) to indicate a block of code.
PYTHON Code Example
1if 5 > 2:
2 print("Five is greater than two!")
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
2 lines
#### Rules of Python Indentation:
- 1Python typically uses 4 spaces per indentation level (avoid mixing tabs and spaces).
- 2All lines within the same block must have the exact same indentation.
- 3If you skip indentation where expected, Python throws an
IndentationError.
#### Python Comments Comments start with a hash symbol # and are ignored by the Python interpreter:
PYTHON Code Example
1# This is a single-line comment
2print("CodeZov") # Inline comment
3
4"""
5This is a multi-line string
6often used for docstrings or
7extended explanations.
8"""
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
8 lines
Proper Block Indentation
1score = 85
2
3if score >= 90:
4 grade = "A"
5elif score >= 80:
6 grade = "B"
7else:
8 grade = "C"
9
10print("Your Grade is:", grade)
Click code or "Edit Code" to edit
Interactive Code Block•Tab = 4 spaces•Ctrl + Enter = Run
10 lines
Note: Each branch under the if/elif/else statements is indented by 4 spaces.
Practice & AssessmentPython Programming Tutorial
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 0 correct(0 attempted)