Python 编程面试题

用 80 道免费 Python 编程面试题练习,每道题都附答案和解析。

等级: Coding Interview 难度: medium 80 道题 60 分钟
回答每道 Python 题,然后查看得分。错题会保存在本机供复习。
连续学习: 0 天 仅保存在此设备
进度 0 / 80
题目 1

Which data type is immutable in Python?

选择一个答案
题目 2

What does len("hello") return?

选择一个答案
题目 3

Which operator checks whether two values are equal?

选择一个答案
题目 4

What is the result of 2 ** 3?

选择一个答案
题目 5

Which method removes the last item from a list and returns it?

选择一个答案
题目 6

What does print(type([])) output?

选择一个答案
题目 7

Which keyword defines a function?

选择一个答案
题目 8

Which values does list(range(3)) produce?

选择一个答案
题目 9

Which built-in function converts a string to an integer?

选择一个答案
题目 10

What is the result of "a" + "b"?

选择一个答案
题目 11

Which collection stores only unique values?

选择一个答案
题目 12

What is the result of 5 // 2?

选择一个答案
题目 13

What is the result of 5 % 2?

选择一个答案
题目 14

Which keyword exits a loop immediately?

选择一个答案
题目 15

Which method adds one item to the end of a list?

选择一个答案
题目 16

What is the output of bool(0)?

选择一个答案
题目 17

Which statement handles exceptions?

选择一个答案
题目 18

What is the result of [1, 2] + [3]?

选择一个答案
题目 19

Which syntax creates a dictionary?

选择一个答案
题目 20

What does dict.get("missing", 0) return when the key is missing?

选择一个答案
题目 21

Which keyword creates a class?

选择一个答案
题目 22

What does self represent inside a Python class method?

选择一个答案
题目 23

Which method is called automatically when a class instance is created?

选择一个答案
题目 24

What is the output of "abc".upper()?

选择一个答案
题目 25

Which function returns the largest item in a list?

选择一个答案
题目 26

What is the result of sum([1, 2, 3])?

选择一个答案
题目 27

Which slice returns the last item of list x?

选择一个答案
题目 28

What is the output of sorted([3, 1, 2])?

选择一个答案
题目 29

Which keyword defines an anonymous function?

选择一个答案
题目 30

What is the result of list(map(str, [1, 2]))?

选择一个答案
题目 31

Which data structure gives the fastest average membership test?

选择一个答案
题目 32

What is the worst-case time complexity of searching for a value in a list?

选择一个答案
题目 33

What is the average time complexity of looking up a key in a dict?

选择一个答案
题目 34

Which statement is true about tuples?

选择一个答案
题目 35

What does isinstance(3, int) return?

选择一个答案
题目 36

Which function returns the number of items in a container?

选择一个答案
题目 37

What is the output of "hello".count("l")?

选择一个答案
题目 38

Which built-in function returns index-value pairs from an iterable?

选择一个答案
题目 39

What is list(zip([1, 2], ["a", "b"]))?

选择一个答案
题目 40

Which keyword is used inside a function to create a generator?

选择一个答案
题目 41

What does next(iter([1, 2])) return?

选择一个答案
题目 42

Which exception is raised by 1 / 0?

选择一个答案
题目 43

Which exception is raised by [1, 2][5]?

选择一个答案
题目 44

Which exception is raised by {"a": 1}["b"]?

选择一个答案
题目 45

What is the output of print(1 == 1.0)?

选择一个答案
题目 46

Which expression evaluates to True?

选择一个答案
题目 47

What is the result of "x" in "example"?

选择一个答案
题目 48

Which method joins a list of strings into one string?

选择一个答案
题目 49

What does set([1, 1, 2]) produce?

选择一个答案
题目 50

Which operator performs floor division?

选择一个答案
题目 51

What is the result of 3 * "ab"?

选择一个答案
题目 52

Which built-in function applies a function to every item and returns an iterator?

选择一个答案
题目 53

What is list(filter(lambda x: x > 2, [1, 2, 3]))?

选择一个答案
题目 54

Which keyword imports a module?

选择一个答案
题目 55

What is the purpose of a docstring?

选择一个答案
题目 56

Which file commonly marks a directory as a Python package?

选择一个答案
题目 57

What does the global keyword do inside a function?

选择一个答案
题目 58

Which built-in function returns an object identity?

选择一个答案
题目 59

What is the output of bool([])?

选择一个答案
题目 60

Which is a valid variable name in Python?

选择一个答案
题目 61

Which of the following built-in types are immutable?

选择一个答案
题目 62

Which methods can add items to a list?

选择一个答案
题目 63

Which expressions create a set?

选择一个答案
题目 64

Which statements are true about dictionaries?

选择一个答案
题目 65

Which built-in functions return iterables?

选择一个答案
题目 66

Which keywords are used for exception handling?

选择一个答案
题目 67

Python lists are zero-indexed.

选择一个答案
题目 68

A Python string can be changed in place.

选择一个答案
题目 69

None is a valid value in Python.

选择一个答案
题目 70

A while loop always runs at least once.

选择一个答案
题目 71

Dictionaries preserve insertion order in Python 3.7 and later.

选择一个答案
题目 72

The is operator compares object identity, not value.

选择一个答案
题目 73

A function without a return statement returns None.

选择一个答案
题目 74

Python uses && for logical AND.

选择一个答案
题目 75

What is the output of print(2 + 3 * 4)? Type the number only.

题目 76

Type the keyword used to define a function.

题目 77

Type the method used to add one item to the end of a list.

题目 78

Type the keyword that raises an exception manually.

题目 79

Type the keyword used to produce values from a generator.

题目 80

What does type(3.5) return? Type the short class name.