Clean Code in Python
Readable code is maintainable code.
Naming Conventions
# Good naming
user_count = 5
def calculate_total_price():
pass
class UserProfile:
pass
# Bad naming
x = 5
def calc():
pass
Use Type Hints
def greet(name: str) -> str:
return f"Hello, {name}"
def process_items(items: list[int]) -> int:
return sum(items)
{# Provenance for articles generated from a source document. Rendered
here rather than stored in the body so it stays accurate and cannot
be edited away, and so the sealed draft stays purely generated. #}
Discussion 0
No comments yet. Be the first to start the discussion!
Leave a Comment