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:24] – [Basic Structures and Constructs] 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> 
- 
-=====Iterate over keys and values of dictionary==== 
-<code python> 
-for k, v in dict.items(): 
-    print(v) 
-</code> 
- 
-<code python> 
-for k in dict.keys(): 
-    print(k + "\n") 
-</code> 
-<code python> 
-for v in dict.values(): 
-    print(v + "\n") 
 </code> </code>
  
 ======Basic Structures and Constructs====== ======Basic Structures and Constructs======
-  * 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.+  * 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> <code python>
 if __name__ == "__main__": if __name__ == "__main__":
Line 74: Line 67:
  
 if "beta" in a: if "beta" in a:
-  pass+    pass
      
 if num > 10: if num > 10:
-  pass+    pass
 elif num < 10: elif num < 10:
-  pass+    pass
 else: else:
-  pass+    pass 
 +</code> 
 + 
 +======Loops/Iteration====== 
 +<code python> 
 +colors = ["red", "green", "blue"
 + 
 +for c in colors: 
 +    print("%s" % c) 
 +</code> 
 + 
 +=====Iterate over keys and values of dictionary==== 
 +<code python> 
 +for k, v in dict.items(): 
 +    print(v) 
 +</code> 
 + 
 +<code python> 
 +for k in dict.keys(): 
 +    print(k + "\n"
 +</code> 
 +<code python> 
 +for v in dict.values(): 
 +    print(v + "\n"
 +</code> 
 + 
 +=====Iterate over indicies and values of sequence===== 
 +<code python> 
 +a = ["a", "b", "c"
 + 
 +for k, v in enumerate(a): 
 + 
 +    print("%s, %s\n" % (k,v))
 </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. That is, testing whether a variable is defined considered harmful.+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.1493069057.txt.gz
  • Last modified: 2017/04/24 21:24
  • by mgupton