Python: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 6: | Line 6: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Whitespace == | == Whitespace == | ||
Uses four spaces instead of brackets e.g. | Uses full colon and four spaces instead of brackets e.g. | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
for i in range(5): | for i in range(5): | ||
Line 12: | Line 12: | ||
print(x) | print(x) | ||
</syntaxhighlight> | |||
== Rules == | |||
* Prefer four spaces | |||
* Never mix spaces and tabs | |||
* Be consistent on consecutive lines | |||
* Only deviate to improve readability | |||
== Help == | |||
help(object) gives help. e.g. for the module math | |||
<syntaxhighlight lang="python"> | |||
help(math) | |||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 04:06, 15 July 2020
Intro
Python 2 and 3 differences
print "fred" // OK Python 2
print("fred") // Not OK Python 2
Whitespace
Uses full colon and four spaces instead of brackets e.g.
for i in range(5):
x = i * 10
print(x)
Rules
- Prefer four spaces
- Never mix spaces and tabs
- Be consistent on consecutive lines
- Only deviate to improve readability
Help
help(object) gives help. e.g. for the module math
help(math)