Gaode's Python interview questions! It's not as easy as a big factory! Xiaobai learn quickly!

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

2. What is the difference between static function, class function, member function and property function?

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

2.2 Examples of class methods:

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

2.3 Examples of attribute methods:

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

3. a=1, b=2, no intermediate variables are used to exchange the values ​​of a and b

Solution: Three forms: direct exchange, addition or XOR

Example:

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

4. Write a function, input a string, and return the results in reverse order: such as: string_reverse('abcdef'), return: 'fedcba' (please use multiple methods to implement, and compare the implementation methods)

Solution: Convert to a list first, reverse the list, and then convert to a string.

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

5. Please use your own algorithm to merge the following two lists in ascending order, and remove duplicate elements:

list1 = [2, 3, 8, 4, 9, 5, 6]

list2 = [5, 6, 10, 17, 11, 2]

Answer: First convert to a set to automatically deduplicate, and then convert to a list.

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

6. Please write the print result:

x = [0, 1]

i = 0

i, x[i] = 1, 2

print(x)

Print result:  [0, 2], python can use continuous assignment, from left to right.

g = lambda x, y = 2, z: x + y ** z

g(1, z=10) = ?

Print result:  Exception, default parameters can only be provided at the end of the formal parameter list, and z needs to provide default parameters.

7. Talk about the problem with the following code snippet

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

answer:

1. Warning: object is a reserved keyword in python and should not be redefined.

2. A class method is a method owned by a class, and the incoming parameter should be cls, not self.

3. Error: The new keyword is not required to instantiate an object in Python.

4. Error: @property means a property, not a method, you don't need to add parentheses "()", just call object.man directly.

5. Error: If you want to override the constructor of the base class, you need to inherit the constructor of the base class and then override it.

6. Extra: Class names should be capitalized as much as possible.

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

Development experience:

Exceptions mainly deal with reading files, and you can also use the with method to read files; they can also be used for network connections. Exceptions can contain a lot of error information for error handling.

Hope everyone can find the job they are looking for!

Gaode's Python interview questions!  It's not as easy as a big factory!  Xiaobai learn quickly!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326813857&siteId=291194637