BazzalSeed / Learn-Python-the-Hard-way

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Learn-Python-the-Hard-way-Notes

  1. 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))
  2. Use \ to escape double quotes (or any other confusing things for python)

    • ex. print ("double"quotes ")
      • output=> double"quotes
  3. Use pydoc for documentation about built-in function/commands/operations for python

  4. 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

Python Wiki for Generators

Stackoverflow discussion about

  1. Usage of read() = > ex16
"""main function."""
with open("test") as inputfile:
    indata = inputfile.read()
with open("outputtest", 'w') as outputfile:
    outputfile.write(indata)
  1. 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

Track Mark 23

About


Languages

Language:Python 100.0%