Python relies on whitespace indentation rather than curly braces {} or keywords (begin/end) to delimit block structures. This indentation model enforces uniform readability across codebases.
flowchart TD
A["Outer Module Scope (0 spaces)"] --> B["Function / Class Def (4 spaces)"]
B --> C["Conditional / Loop Block (8 spaces)"]
C --> D["Nested Block (12 spaces)"]
: marks the start of an indented block (functions, classes, loops, conditionals, try/except).from typing import List
def process_scores(scores: List[int], passing_grade: int = 70) -> List[str]:
"""Evaluate student scores and return classification results."""
results: List[str] = []
for score in scores:
# Indented 8 spaces (inside function + inside loop)
if score >= passing_grade:
status = f"Pass ({score})"
else:
status = f"Fail ({score})"
results.append(status)
return results
if __name__ == "__main__":
sample_scores = [85, 62, 90, 45, 78]
summary = process_scores(sample_scores)
print("Evaluation Results:", summary)
TabError syntax exception during parsing.() instead of using backslashes \ for line wrapping.Write a function check_even_odd(numbers: list[int]) -> None that iterates over a list, uses if/else with 4-space indentation, and prints whether each integer is even or odd.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
You've completed this section! Take a quick 5-question quiz to check your understanding.