Char 14 iterators and parsers
Iterative: An object that supports ITER
Iterator: An object returned by ITER that supports next (I)
These functions are automatically called by the Python iteration tool, and we can also manually apply the iteration protocol
Char 15 Documentation
1 writing Python's documentation resources
Python Documentation Resources |
|
Form |
Role |
# Notes |
Documents in the file |
Dir function |
List of available properties in an object |
Document string: __doc__ |
Documents attached to a file on an object |
Pydoc:help function |
Interactive Help for objects |
pydoc:html Report |
Module documentation in the browser |
Standard Manual |
Official Language and library instructions |
Site Resources |
Online tutorials, examples, etc. |
2 The dir result of any built-in type contains a set of properties that are related to the implementation of the type
3 document String that appears at the beginning of the file and at the start of its functions and classes
classDemo (object):" "Demo Desc" " defTest (self):" "desc:only Test:return:" " Print('Test')Print(Demo.)__doc__)Print(Demo (). Test.__doc__)" "Run Result Demo Desc desc:only test:return:" "
4 common pitfalls for writing code
1) Don't forget the colon.
2) Start with the first line
3) Blank lines are important at the interactive mode prompt
4) indent to be consistent
5) do not write C code in Python
6) Use a simple for loop instead of while or range
For is faster than while, because Python handles index operations internally for a simple for loop
7) Be aware of mutable objects in assignment statements
8) do not expect in the distance the function of the Fat object will return the result
Eg:list.sort () returns none, List2 = sorted (lsit)
9) Be sure to use the () Call function
10) Do not use extensions or paths in import and reload
Eg:model name:basecal.py, import basecal [Yes]; Import basecal.py [NO]
Python Learning Manual, Char 14-15