One . choice question ( Each question 1 branch , common 20 branch )

* Which of the following statements is in the Python It's illegal in China ? ( B )
A. x = y = z = 1 B. x = (y = z + 1)
C. x, y = y, x D. x += y
2. about Python memory management , What is wrong with the following statement ( B )
​ A. Variables do not have to be declared in advance B. Variables are used directly without creating and assigning values first
​ C. Variables do not need to be typed D. have access to del Release resources

*
stay Python3 The result is ? ( D )
>>> world="world" >>> print "hello"+ world
A. helloworld B. "hello"world

C. hello world D. syntax error

*
Which of the following is not Python Legal identifier ( B )
A. int32 B. 40XL C. self D. name

*
Which of the following statements is wrong ( AD )
A. Except dictionary type , All standard objects can be used for Boolean testing
B. The Boolean value of an empty string is False
C. The Boolean value of an empty list object is False
D. The value is 0 The Boolean value of any numeric object of is False

*
The value of the following expression is True What's important is that ( A )
A. 5+4j > 2-3j B. 3>2>2
C. (3,2)< (‘a’,‘b’) D. ‘abc’>‘xyz’

*
Python The unsupported data type is ( A )
A. char B. int C. float D. list

*
type(1+2L*3.14) The result is : ( C )
A. <type ‘int’> B. <type ‘long’>
C. <type ‘float’> D. <type ‘str’>

*
The following statement about string is wrong ( B )
A. Characters should be treated as being of length 1 String of
B. String with \0 Marks the end of the string
C. You can use single quotation marks , You can also create strings with double quotes
D. Special characters such as line feed and carriage return can be included in the triple quotation string

*
The following statements that cannot create a dictionary are ( C )
A. dict1 = {}
B. dict2 = { 3 : 5 }
C. dict3 = dict( [2 , 5] ,[ 3 , 4 ] )
D. dict4 = dict( ( [1,2],[3,4] ) )

*
The following statement that cannot create a collection is ( C )
A. s1 = set () B. s2 = set (“abcd”)
C. s3 = (1, 2, 3, 4) D. s4 = frozenset( (3,2,1) )

*
following Python The statement is correct ( D )
A. min = x if x < y else y B. max = x > y ? x : y
C. if (x > y) print x D. while True : pass

*
Which of the following methods allocates memory for creation ( AB )
A. new () B. init()
C. del() D. There is no right answer

*
Which of the following objects does not belong to Itarable Of ( D )
A. list B. tuple
C. dict D. float

*
About how to create a process , What's wrong is that (D )
A. fork B. Process
C. Process Subclass of D. It's all wrong

*
About type conversion , What are the mistakes ( Multiple choice ) ( C )
A. int <-> float B. tuple <-> list
C. list<-> dict D. str <-> list

*
Which of the following types cannot be sliced ( D )
A. str B. list
C. tuple D. dict

*
Which of the following is a variable object ( B )
A. value type (int,float) B. list
C. tuple D. str

*
Which of the following methods can be implemented to make an object called like a function ( C )
A. str() B. iter()
C. call() D. next()

*
Which of the following is not an object-oriented feature ( D )
A. encapsulation B. inherit
C. polymorphic D. reunite with

Two . Short answer questions ( Each question 5 branch , common 40 branch )

**

<>1. Please briefly describe your understanding of object orientation

**

Object oriented programming —object oriented
programming, abbreviation :OOP, It's a programming idea .OOP Take the object as the basic unit of a program , An object contains data and functions that manipulate data . The emergence of object-oriented greatly improves the efficiency of programming , The reusability of programming is increased .
python Important terms of object oriented :
  1. polymorphic (polymorphism): A function has many forms , There are many ways to call a method , But the way to show it is different .
  2. inherit (inheritance) The child inherits some of the functions of the parent , Show some connection in the program
  3. encapsulation (encapsulation) Encapsulate functions or functions that need to be reused , Convenient for other programs to call directly
  4. class : A collection of objects with the same data or method
  5. object : An object is a concrete instance of a class

**

<>2. What are deep copy and shallow copy

**

Shallow copy :

Copy of memory address , Let the target object pointer and the source object point to the same memory space . be careful : When the memory is destroyed , Pointer to object , It has to be redefined , Can be used

Deep copy : Deep copy refers to , Copy the specific content of the object , Second, the memory address is allocated autonomously , After copying, the values of the two objects are the same , But the memory address is different , The two object pages do not affect each other , Non interference

**

<>3. Please give a brief introduction Python The memory management mechanism in

**

Python use gc Module processing python Objects and python The work of garbage collector

gc.enable()—— Automatic garbage collection ;
gc.disable()—— No automatic garbage collection ;
gc.set_threshold()—— set up python Threshold of garbage collection ;
gc.set_debug()—— Set debugging flag for garbage collection , Debug information is written std.err;

gc.get_objects()—— Returns a list of all objects tracked by the collector , The returned list is not included .

Python The memory management mechanism of the system mainly includes three aspects : Reference counting mechanism , Garbage collection mechanism , Memory pool mechanism

**

<>4. Please write the way to create the generator ( It's better to use code )

**

Mode one : Change the bracket of list generation into bracket

List generation a = [x*2 for x in range(100000000000)]

generator a = (x*2 for x in range(100000000000))

When calling next(a)
def creatnum(): a,b = 0,1 for i in range(5): yield b a,b = b,a+b
**

<>5. Please give a brief introduction dict The characteristics of

**

In the dictionary key The value of cannot be changed ,value The value of can be changed ;

Because the dictionary is used to save data Hash Storage mode Therefore, the dictionary cannot use slicing method

**

<>6. Please give a brief introduction 4G How to read the memory of 5G Data for

**
#1 use python The generator of , Read a small piece of data # generator : have yield The function is the generator , Is a function that returns an iterator #
iterator : Objects that know where to traverse , Yes iter() and next() method # Code examples : def get_lines(): # generator with open(
'file5G.py', 'r') as f: while True: data = f.readlines(100) if data: yield data
else: break f = get_lines() # Iterator objects print(next(f)) print(next(f)) print(next(f))
#2 Linux Of split command # You can split the file into small files for operation # effect :split Divide a file into files of specified size # Usage grammar : split
[–help][–version][-< Number of rows >][-b < byte >][-C < byte >][-l < Number of rows >][ Files to cut ][ Output file name ] #
The common options are -b Cut by byte ,-l Cut by number of lines # Input command in black window , Use examples : python@ubuntu:~/Desktop$ split -l 2
requirements.txt re.txt # meaning : Cut in two lines requirements.txt file , The name of the cut file is re.txt. #
A lot will be generated after carriage return re file , It's two lines of code
**

<>7. sketch read. readline. readlines The difference between

**

read: Read entire file

read([size]) Method to read from the current location of the file size Bytes , If no parameters size, It means reading to the end of the file , It ranges from string objects
f = open("a.txt") lines = f.read() print(lines) print(type(lines)) f.close()
Output results :
Hello Welcome What is the fuck... <type 'str'> # String type
readline: Read next line , Using generator methods .**

It can be seen from the literal meaning , The method reads one line at a time , therefore , Small memory consumption when reading , More suitable for large files , This method returns a string object .
def pyReadLine(filename): file_object1 = open('a.txt','r') try: while True:
line= file_object1.readline() if line: print ("line=",line) else: break finally:
file_object1.close()
Output results :
<type 'str'> Hello Welcome What is the fuck...
readlines: Read the entire file to an iterator for us to traverse

readlines() Method to read all lines of the entire file , Save in a list (list) In variable , Each line as an element , But reading large files will take up more memory .
f = open("a.txt") lines = f.readlines() print(type(lines)) for line in lines:
print(line) f.close()
Output results :
<type 'list'> Hello Welcome What is the fuck...
**

<>8. The difference between instance property and class property and instance method and class method are introduced , The difference between static methods

**

The difference between class property and instance property

stay Python Everything in the world is the object , Class is a special object, that is class object , The properties that describe a class are called class properties , It belongs to the class . Class property has only one copy in memory , All instance objects are common , stay __init__ External definition .

Instance properties : Used to describe instance objects created by a class , It needs to be accessed through objects , Save one copy in the memory of each object , stay __init__ Method internal definition

Example method , Class method , The difference between static methods
All three methods are stored in the memory of the class , Different callers .

Instance methods are called by objects , At least one self parameter ,self Represents a reference to an object .

Class methods are called by classes , At least one cls parameter , And they need decorators @classmethod modification

Static methods are called by classes , No parameters are required , Need a decorator @staticmethod modification

Technology