Content Today
Copy depth
File Operations
Review and supplemental content
1. Recap
Computer Basics
coding
grammar
if/while/for
type of data
type/id/range
Operators
2. interview questions
a. Systems of line with what is?
The difference b.py2 and py3
c. Operators
d.is distinction and == d
The list of data types in python What are the methods?
Content Today
1. Copy shades
Shallow copy copy.copy (): Only copy of the first layer.
Deep copy copy.deepcopy (): copy all types of variable nested hierarchy.
a data type for int + str + bool, all data is immutable, is to open up a new theory of storage space, but because of the small pool of data, use the same copy depth memory address, please note.;
b. for the list + set + dic
There is only the case where the deep copy of the variable in the nested type of role.
Shallow copy: just copy the first layer, the values of the elements point to the source address.
Deep copy: a complete copy.
c. special circumstances
For tuples are immutable data types, shades will not re-open a new copy of the memory address, but if there exists a variable element, is to re-open a new memory address.
2. File operations
a. Open
r: read-only
w: only write, write first before will empty the file, if the file does not exist, it will directly create, if there is to empty
a: append only, that can only be written if the file does not exist, will create
Note: r Mode: If the file does not exist on the error; the default w: If the file does not exist is created, the presence on the first empty; in a mode, if the file does not exist is created, the file contents can not be read;
r +: readable and writable
Read: The default start reading from the cursor position is 0, you can also seek to adjust the position of the cursor (in bytes to seek a);
Write: Write start from the position of the cursor, you can also seek to adjust the position of the cursor ( Note: When the cursor is still behind the content, write and overwrite the contents of the cursor behind )
w +: first read-after-write
Read: the default cursor is always in the back or 0 written (have not started to write something), you can also seek to adjust the position of the cursor;
Write: first empty the file, and then start writing content
a +: appendable readable
Read: the default cursor is always at the edge of the final contents of the file, you can also seek to adjust the position of the cursor, and then go read;
Write: always written in the final edge, no matter how moving the cursor
b. Operation
Read: read () / read (2) [which is represented by the character data] / readlines ()
写:write
# ###################################### read
# file_object = open ( 'log.txt ', mode =' r ', encoding =' utf-8 ')
all the contents of the file is read into memory #
# data = file_object.read ()
# two characters from the document reading the current cursor position rearwardly
# data = file_object.read (2)
all the contents of the file # read into memory, and dividing each line according to the list.
DATA_LIST file_object.readlines = # ()
# Print (DATA_LIST)
# If after reading a particularly large file (**********)
# for Line in the file_object:
# line.strip Line = ()
# Print (Line)
# file_object.close ()
c. Close close