What is code formatting?
Writing clean, consistent code is important. Code formatting means organizing your code so it’s easy to read and follows Python’s style guidelines.Basic formatting principles
Follow these basic rules for readability:Indentation
Use 4 spaces for indentation (not tabs):Spacing
Add spaces around operators and after commas:Blank lines
Use blank lines to separate functions and logical sections:Line length
Keep lines under 80-100 characters. Break long lines for readability:Later in the course, you’ll learn about Ruff - a tool that automatically formats your code. But understanding these basics first helps you write better code naturally.
Automatic formatting with Ruff
Want to format your code automatically? Check out the Ruff guide in the tools section:Code quality with Ruff
Automatically format and lint your code
What’s next?
Now that you understand formatting, let’s learn about variables!Variables
Learn how to store and use data in Python