Join the fun: http://www.SiliconDojo.com
Support us with at: http://www.donorbox.com/etcg
Python is designed to be an easy to read language. Unlike languages such as Javascript and PHP where you can have ugly, hard to read code that still works the idea with Python is that the required formatting lends the code to be easy to read.
The Syntax of Python is the requirement to use indentations for code blocks, and other requirements of how you write code that if are not correct the code will fail.
Styling is how you decide to write code withing the Syntax restrictions. Whether you use tabs or spaces to define code blocks. Whether you use camelCase or snake_case for naming variables and whether you write long lines of code that your IDE word wraps, or you format the code to fit on a page.
PEP 8 is Styling Guide that is supposed to be used to determine the styling of your Python code. It's not required that these standards be followed, but the guidelines are very practical.
PEP 8
https://peps.python.org/pep-0008/
Indentations for Code Blocks
Code blocks are identified by indentations.
if var 10:
print('something')
for x in list:
print(x)
The indents can either be 4 spaces or one tab.
Spaces are preferred because the size of a space is always the same, whereas tab length can change depending on system settings.
Tabs can be easier to type.
You cannot mix tabs and spaces for indentation in a script.
Variable and Function Name Convention
Python PEP 8 Styling uses the Snake Case for variable naming. Letters should be all lower case.
snake case
variable_name = 'bob'
Module and Function Conflict in Namespace
When you name variables make sure they do not share the same name as a module or a function. Variable names such as time will cause issues if you import the time module later.