[Python] book chapter, python basis

First, the basic syntax:

What is 1, the code data is immutable modify Throws: TypeError exception will be thrown

2, a = 1, b = 2 exchange without intermediate variables a and b values

a = a+b

b = a -b

a = a -b

3, brief understanding of the input () function: the python3 in input () is to obtain the user's input, the user input regardless of what type, string type are obtained, but in the python2 input () input What type of data, access to data is what type

 

4, the difference between the range and xrange?

Both use the same, the difference is the result of range returns a list, xrange returns a generator, the former is to open up a direct memory space to save the list, while circulating the latter is used only when you use will open up memory space

When the list is long, with xrange better performance, but have been discarded xrange python 3 function, and with alternative range

 

5, read: read the entire file readline: reads the next line, use the builder methods readlines: read the entire file into an iterator for us to traverse

 

6, exception: The raise method can throw custom exception

 

7, commonly used python library What?

os: Operating System time: Time random: random pymysql: database connection threading: Thread queue: queues

 

8, a popular third-party libraries What?

django flask requests selenium xadmin celery md5 pip install installation of third-party libraries belong

 

9, assignment, deep copy and shallow copy of the difference?

In python, assignment object is simply a reference to the new assignment will not open up memory space, it's just a copy of the referenced object, that is in addition to the b name, no other memory overhead, but also a modified It is a change in the b

Similarly amended b will affect a

 

Shallow copy copy (): creates a new object, the contents of the original non-reference the object itself, but the original object references within the first layer of the object

Deep copy deepcopy (): deep copy element copies of all objects, including multiple nested elements, and therefore, it is time and space overhead higher

 

10, init and new differences

init is after the object is created, an object is initialized

It is to create a new object before the object is created, and returns the object to the  init 

 

11, and explain what os.path sys.path represent?

os.path: a main path to a file operation of the system

sys.path: main parameters of the operation of the system environment interpreter python (python interpreter dynamically change the search path)

 

12, a common method in python os module?

    https://www.runoob.com/python/os-file-methods.html

 

13、

 

Guess you like

Origin www.cnblogs.com/yuanyuan2017/p/11511149.html