aboutsummaryrefslogtreecommitdiffstats
path: root/templates/site/tutorials/python/py-style.md
diff options
context:
space:
mode:
Diffstat (limited to 'templates/site/tutorials/python/py-style.md')
-rw-r--r--templates/site/tutorials/python/py-style.md58
1 files changed, 28 insertions, 30 deletions
diff --git a/templates/site/tutorials/python/py-style.md b/templates/site/tutorials/python/py-style.md
index 2a68fac..bf96f59 100644
--- a/templates/site/tutorials/python/py-style.md
+++ b/templates/site/tutorials/python/py-style.md
@@ -20,7 +20,7 @@ This is really just because I like how C does it. And Cpython's C-based so
why not?
Like so:
- ```
+ ```code
string = "This is a phrase"
word = "word"
cur_char = 'a'
@@ -31,7 +31,7 @@ Like so:
The only exception is for strings with quotes in them (anything to avoid
escapes, really)
- ```
+ ```code
quoted_string = (
'"You miss 100% of the shots you don't take - Wayne Gretsky" - Michael Scott'
)
@@ -41,30 +41,30 @@ That brings me to my next point.
## 2) Long strings belong in parentheses
As in:
- ```
- longboi = (
- "This is a really long string usefull when making help menus. Be\n"
- "sure to leave s space at the end of each line, or add a new line\n"
- "when needed.\n"
+```code
+longboi = (
+ "This is a really long string usefull when making help menus. Be\n"
+ "sure to leave s space at the end of each line, or add a new line\n"
+ "when needed.\n"
- "Try your best to keep formatting accurate like this."
- )
- ```
+ "Try your best to keep formatting accurate like this."
+)
+```
## 3) Tabs are four spaces and spaces are *ALWAYS* prefered to tabs
Again, see PEP8.
## 4) Always add spaces between arithmetic, but never for brackets
It's a pain to read:
- ```
+ ```code
1/(2*sqrt(pi))*exp(x**2)
```
Do this
- ```
+ ```code
1 / (2 * sqrt(pi)) * exp(x ** 2)
```
The same goes for logic operators
- ```
+ ```code
true & false ^ true
```
@@ -72,22 +72,20 @@ The same goes for logic operators
This is python. Unless there's a compatibility thing (like a library's
code was written that way, or it matches an API variable),
snake_case is preferred.
- ```
-
- user_input = int(input()) # variable
- MAX_INPUT = 1000 # constant
- def judge_input(_input, _max): # function
- if _max > _input:
- print("Too big!")
-
- judge_input(user_input, MAX_INPUT
- class Input_Judger: # a class
- # etc etc
- ```
+```code
+user_input = int(input()) # variable
+MAX_INPUT = 1000 # constant
+def judge_input(_input, _max): # function
+ if _max > _input:
+ print("Too big!")
+
+judge_input(user_input, MAX_INPUT
+class Input_Judger: # a class
+ # etc etc
+```
Example exception
- ```
- # this doesn't actually work, but you get the idea
- r = requests.get("www.debian.org")
- pageSize = r.json()['pageSize'] # camel case ok
- ```
+```code
+# this doesn't actually work, but you get the idea
+r = requests.get("www.debian.org")
+pageSize = r.json()['pageSize'] # camel case ok```