Explorar el Código

Merge branch 'master' of https://io.monkeybox.org/git/fdamstra/python_notes

Fred Damstra hace 7 años
padre
commit
57eabd9a49
Se han modificado 2 ficheros con 18 adiciones y 1 borrados
  1. 14 0
      examples/immutable.py
  2. 4 1
      examples/simplefunction.py

+ 14 - 0
examples/immutable.py

@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+""" 
+Demonstrates an annoying feature of mutable defaults vs
+immutable defaults.
+"""
+
+def ChangeList(list = []):
+    list.append("Fred was here")
+    return list
+
+if __name__ == "__main__":
+    print(ChangeList())
+    print(ChangeList())
+

+ 4 - 1
examples/simplefunction.py

@@ -1,8 +1,11 @@
+#!/usr/bin/env python3
+""" A simple example of function declarations and main.  """
+
 def example(firstargument, secondargument, thirdargument="N/A"):
     """ Prints a string based on the two arguments. """
     # This is python3.6 syntax:
 #    print(f"{firstargument} is the first argument.")
-    print("{} is the first argument.".format(firstargument))
+    print("{a} is the first argument.".format(a = firstargument)) # Name the argument if you want
     print("{} is the second argument.".format(secondargument))
     print("{} is the third argument.".format(thirdargument))