Python Learning Manual, Char 14-15

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.