Python Coding Interview Questions

Practice 80 free Python coding interview questions with answers and explanations.

Level: Coding Interview Difficulty: medium 80 questions 60 min
Answer each Python question, then check your score. Wrong answers are saved locally for review.
Day streak: 0 days Saved only on this device
Progress 0 / 80
Question 1

Which data type is immutable in Python?

Select an answer
Question 2

What does len("hello") return?

Select an answer
Question 3

Which operator checks whether two values are equal?

Select an answer
Question 4

What is the result of 2 ** 3?

Select an answer
Question 5

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

Select an answer
Question 6

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

Select an answer
Question 7

Which keyword defines a function?

Select an answer
Question 8

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

Select an answer
Question 9

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

Select an answer
Question 10

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

Select an answer
Question 11

Which collection stores only unique values?

Select an answer
Question 12

What is the result of 5 // 2?

Select an answer
Question 13

What is the result of 5 % 2?

Select an answer
Question 14

Which keyword exits a loop immediately?

Select an answer
Question 15

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

Select an answer
Question 16

What is the output of bool(0)?

Select an answer
Question 17

Which statement handles exceptions?

Select an answer
Question 18

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

Select an answer
Question 19

Which syntax creates a dictionary?

Select an answer
Question 20

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

Select an answer
Question 21

Which keyword creates a class?

Select an answer
Question 22

What does self represent inside a Python class method?

Select an answer
Question 23

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

Select an answer
Question 24

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

Select an answer
Question 25

Which function returns the largest item in a list?

Select an answer
Question 26

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

Select an answer
Question 27

Which slice returns the last item of list x?

Select an answer
Question 28

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

Select an answer
Question 29

Which keyword defines an anonymous function?

Select an answer
Question 30

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

Select an answer
Question 31

Which data structure gives the fastest average membership test?

Select an answer
Question 32

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

Select an answer
Question 33

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

Select an answer
Question 34

Which statement is true about tuples?

Select an answer
Question 35

What does isinstance(3, int) return?

Select an answer
Question 36

Which function returns the number of items in a container?

Select an answer
Question 37

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

Select an answer
Question 38

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

Select an answer
Question 39

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

Select an answer
Question 40

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

Select an answer
Question 41

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

Select an answer
Question 42

Which exception is raised by 1 / 0?

Select an answer
Question 43

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

Select an answer
Question 44

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

Select an answer
Question 45

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

Select an answer
Question 46

Which expression evaluates to True?

Select an answer
Question 47

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

Select an answer
Question 48

Which method joins a list of strings into one string?

Select an answer
Question 49

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

Select an answer
Question 50

Which operator performs floor division?

Select an answer
Question 51

What is the result of 3 * "ab"?

Select an answer
Question 52

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

Select an answer
Question 53

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

Select an answer
Question 54

Which keyword imports a module?

Select an answer
Question 55

What is the purpose of a docstring?

Select an answer
Question 56

Which file commonly marks a directory as a Python package?

Select an answer
Question 57

What does the global keyword do inside a function?

Select an answer
Question 58

Which built-in function returns an object identity?

Select an answer
Question 59

What is the output of bool([])?

Select an answer
Question 60

Which is a valid variable name in Python?

Select an answer
Question 61

Which of the following built-in types are immutable?

Select an answer
Question 62

Which methods can add items to a list?

Select an answer
Question 63

Which expressions create a set?

Select an answer
Question 64

Which statements are true about dictionaries?

Select an answer
Question 65

Which built-in functions return iterables?

Select an answer
Question 66

Which keywords are used for exception handling?

Select an answer
Question 67

Python lists are zero-indexed.

Select an answer
Question 68

A Python string can be changed in place.

Select an answer
Question 69

None is a valid value in Python.

Select an answer
Question 70

A while loop always runs at least once.

Select an answer
Question 71

Dictionaries preserve insertion order in Python 3.7 and later.

Select an answer
Question 72

The is operator compares object identity, not value.

Select an answer
Question 73

A function without a return statement returns None.

Select an answer
Question 74

Python uses && for logical AND.

Select an answer
Question 75

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

Question 76

Type the keyword used to define a function.

Question 77

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

Question 78

Type the keyword that raises an exception manually.

Question 79

Type the keyword used to produce values from a generator.

Question 80

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