Day 5 python learning Notes

1 python which objects to support traversal?

    Iterative protocol supported object, such characteristics of an object is () method supports __next __. List, tuple, dictionary, documents support this feature.

2 and read the file traversal, using function readlines () file elements can be read and placed into a list, but this is not the recommended method of accounting for such a large memory processing, using an iterator only take up a small amount of memory.

F 3 is not a determination target using the statement iterator

iter(f) is f

    Returns True, it is, or it is not, use the statement to generate an iterator

F1 = travel (F)

    At this point f1 it is already an iterator object

    Note: that is, raw file iterator, iter is required to generate a list, in a for loop, will be automatically generated iterator iter, usually use can be called iter () manually generated.

4 Derivation

    4.1 the return type, external symbols determined by the statement, such as

[x * 2 for x in data]

        Return to the list

    4.2 filter conditions, the basic format is:   

[x * 2 for x in data if x % 2 == 0]

5 Functions

    5.1 Definitions:

def function name (parameter 1, parameter 2, ...): function body

    5.2 call:

Function name (actual parameter)

    5.3 Variable

        global、built-in、enclosure、local

    5.5 parameter passing

        Immutable types: int, float, string, and other tuples, the operation does not affect the original function value

        Variable types: lists, dictionaries, tables, etc., within the function affect the operation of the original value, if you do not affect the original value, you need to use a copy

Guess you like

Origin www.cnblogs.com/zhuome/p/11313078.html