Skip to the content.

PEP 8 — Python Style Guide

The official Python style guide.
Keep code clean, consistent, and readable. Importante para seu future self.


1. Code Layout

Imports


2. Naming Conventions

Type Convention Example
Variable / Function lower_case_with_underscores get_data()
Class CamelCase AgentModel
Constant ALL_CAPS MAX_SPEED = 10
Module / Package short_lowercase tools, data_utils

3. Whitespace Rules

  x = (1, 2, 3)
total = a + b

4. Strings and Docstrings

def add(a, b):
    """Return the sum of a and b."""
    return a + b

5. Comments

# Calculate total cost
total = price * quantity  # Apply unit price

Voltem a esses abaixo mais na frente no curso…

🧮 6. Functions and Classes

def add_item(item, items=None):
    if items is None:
        items = []
    items.append(item)
    return items

⚙️ 7. Comparisons and Conditionals

if result is None:
    return

if flag:
    execute_task()

🧩 8. Line Breaks

total = (
    first_value
    + second_value
    + third_value
)