Python interview questions

1. Python basics#

1.1 Basic grammar##

1.1.1 Input and output###

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.

1.1.2 Conditions and cycles###

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

1.1.3 File operations###

Recommended Posts

Python interview questions
Python interview questions summary
Python classic interview questions two
Python interview questions: string concatenation
Python interview questions collection (three)
Python answers questions
Python interview assault
Python classic interview question one​
LeetCode brushing questions summary python3
Python classic programming questions: string replacement
Python multithreading
Python CookBook
Python FAQ
Python3 dictionary
Python3 module
python (you-get)
Python string
Python basics
Python descriptor
Python exec
Python notes
CentOS + Python3.6+
Python advanced (1)
Python decorator
Python IO
Python multithreading
Python3 list
Python multitasking-coroutine
python introduction
Python basics
07. Python3 functions
Python basics 3
Python multitasking-threads
Python functions
python sys.stdout
python operator
Python entry-3
Centos 7.5 python3.6
Python string
python queue Queue
Python basics 4
Python basics 5