1.1. What problems will be found if you want to modify immutable data in the code? What exception will be thrown?
The code will not run normally, throw a TypeError exception
1.2. a=, b=2 do not exchange the values of a and b with intermediate variables?
# method one
a = a+b
b = a-b
a = a-b
# Method Two
a=a^b
b=b^a
a=a^b
# Method Three
a,b=b,a
1.3. What method does print call the bottom layer in python?
# The print method calls sys by default.stdout.write method, that is, print characters to the console
1.4. What is the output of the following code?
#
1.5. Briefly describe your understanding of the input() function?
# In Python3,input()Get user input, regardless of what the user enters,All obtained are of string type.
# In python2,raw_input()And input(),raw_input()And input in python3()The effect is the same,input()What data type is entered, and what data type is obtained.
2.1 What is the difference between range and xrange?
# Both have the same usage,The difference is that the result returned by range is a list,The result of xrange is a generator. The former is to directly open up a memory space to save the list, and the latter is to use while looping. The memory space is opened up only when used, so when the list is very long, the performance of using xrange is better than range
2.2 The output of the following Python program
for i inrange(5,0,-1):print(i)
# 54321
Talk about the shade copy?
# Shallow copy:A new space will be created in the memory to store the copy list, but the content in the list still uses the memory address of the previous object
Recommended Posts