python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
python [2017/04/24 21:08] – [Determine if variable is defined] mguptonpython [2023/03/20 17:33] (current) – [Python] mgupton
Line 1: Line 1:
 ======Python====== ======Python======
 +  * [[https://www.python.org/dev/peps/pep-0008/|PEP 8 -- Style Guide for Python Code]]
 +  * [[https://pep8.org/]]
 +
 +  * [[Python Modules and Packages]]
 +  * [[Python Tools]]
 +  * [[python:Handling Dates]]
 +
 +
 ======Core Elements & Constructs====== ======Core Elements & Constructs======
 =====Lists===== =====Lists=====
Line 41: Line 49:
    b    b
 => {} => {}
 +</code>
 +
 +======Basic Structures and Constructs======
 +  * If the %%__name__%% variable is set to %%__main__%% the module is being loaded as a main script and program entry point. Otherwise it's being loaded as a library module.
 +<code python>
 +if __name__ == "__main__":
 +   print("Hello World.")
 +else:
 +   pass
 +</code>
 +
 +======Conditionals======
 +<code python>
 +num = 100
 +
 +a = ["alpha", "beta", "gamma"]
 +
 +if "beta" in a:
 +    pass
 +  
 +if num > 10:
 +    pass
 +elif num < 10:
 +    pass
 +else:
 +    pass
 +</code>
 +
 +======Loops/Iteration======
 +<code python>
 +colors = ["red", "green", "blue"]
 +
 +for c in colors:
 +    print("%s" % c)
 </code> </code>
  
Line 58: Line 100:
 </code> </code>
  
-======Basic Structures and Constructs====== +=====Iterate over indicies and values of sequence=====
-  * If the %%__name__%% variable is set to %%__main__%% the module is being loaded as a program entry point. Otherwise it's being loaded as a library module.+
 <code python> <code python>
-if __name__ == "__main__"+["a", "b""c"]
-    print("Hello World."+
-else: +
-    pass +
-</code>+
  
-======Conditionals====== +for k, v in enumerate(a):
-<code python> +
-num = 100+
  
-a = ["alpha", "beta""gamma"+    print("%s%s\n% (k,v))
- +
-if "beta" in a: +
-  pass +
-   +
-if num > 10: +
-  pass +
-elif num < 10: +
-  pass +
-else: +
-  pass+
 </code> </code>
  
Line 87: Line 112:
 ======Determine if variable is defined====== ======Determine if variable is defined======
 <WRAP round info> <WRAP round info>
-It might be a code smell/anti-pattern to be testing whether or not an identifier is defined.+It might be a code smell/anti-pattern to test whether or not an identifier is defined. That is, testing whether a variable is defined considered harmful.
 </WRAP> </WRAP>
 =====Method 1====== =====Method 1======
Line 116: Line 141:
 </code> </code>
  
 +=======Resources/References======
 +  * [[http://docs.python-guide.org/en/latest/|The Hitchhiker’s Guide to Python]]
 +  * [[https://realpython.com/|Real Python]], tutorials and other learning resources
  
  • python.1493068110.txt.gz
  • Last modified: 2017/04/24 21:08
  • by mgupton