-
String formatting
- %d will format a number for display
- %s will insert the presentation string representation of the object (i.e. str(o))
- %r will insert the canonical string representation of the object (i.e. repr(o))
-
Use \ to escape double quotes (or any other confusing things for python)
- ex. print ("double"quotes ")
- output=> double"quotes
- ex. print ("double"quotes ")
-
Use pydoc for documentation about built-in function/commands/operations for python
-
WITH in python => with handle the lifecycle of the object automatically, destroys it in the end. Calssic example is used with open file
with open('output.txt', 'w') as f: f.write('Hi there!')
eg. ex16 5. Iterator, Generator and Yield
Stackoverflow discussion about
- Usage of read() = > ex16
"""main function."""
with open("test") as inputfile:
indata = inputfile.read()
with open("outputtest", 'w') as outputfile:
outputfile.write(indata)
- double star and single star for parameters
def function1(**args)
def function2(*args)
The *args will give you all function parameters as a tuple The **kwargs will give you all keyword arguments except for those corresponding to a formal parameter as a dictionary. test_doublestar.py