Knowledgebase

Writing Readable Python Print

  • python, troubleshooting, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Style that matters.

THE PRINCIPLE

Code is read far more often than written.

WHAT THE COMMUNITY STANDARD COVERS

Indentation: four spaces

Naming conventions Line length Spacing around operators Import placement

WHY FOLLOW IT

Any Python programmer can then read your code immediately.

WHAT TO NAME WELL

Everything.

A good name removes the need for a comment.

WHAT TO KEEP SHORT

Functions Lines The distance between where a name is defined and used

WHAT TO AVOID

Clever one-line solutions nobody can read Abbreviations only you understand Deep nesting

WHAT TO PREFER

Several clear steps over one compact expression.

WHAT TOOLS EXIST

Formatters that apply style automatically Checkers that flag problems

WHAT TO ADOPT

A formatter, so style is never debated.

WHAT THAT SAVES

Time, and arguments.

WHAT TO CHECK

Whether someone unfamiliar could follow it.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot