Python interview Flashcards

Common questions for python positions (36 cards)

1
Q

What is the output of print(type(5)) in Python?

A

<class ‘int’>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: Lists in Python are immutable.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What keyword is used to define a function in Python?

A

def

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Fill in the blank: In Python, a ________ is a block of code that only runs when it is called.

A

function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the ‘self’ parameter in class methods?

A

To refer to the instance of the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following is a mutable data type in Python? (A) Tuple (B) List (C) String

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the ‘len()’ function do?

A

Returns the length of an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True or False: A Python dictionary can have duplicate keys.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What method would you use to add an item to a list?

A

.append()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the output of the expression 3 * ‘abc’?

A

‘abcabcabc’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which symbol is used for comments in Python?

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What built-in function can be used to convert a string to an integer?

A

int()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Fill in the blank: A ________ loop is used to iterate over a sequence in Python.

A

for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: The ‘break’ statement is used to exit a loop in Python.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the difference between ‘==’ and ‘is’ in Python?

A

’==’ checks for value equality, ‘is’ checks for identity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the ‘try’ keyword do in Python?

A

It begins a block of code to handle exceptions.

17
Q

What will be the output of the following code: print([1, 2, 3] + [4, 5])?

A

[1, 2, 3, 4, 5]

18
Q

Fill in the blank: The ________ keyword is used to handle exceptions in Python.

19
Q

Which method would you use to remove an item from a dictionary?

20
Q

What is a lambda function?

A

A small anonymous function defined with the ‘lambda’ keyword.

21
Q

What is the output of the expression ‘Hello’.upper()?

22
Q

True or False: Python supports multiple inheritance.

23
Q

What is the purpose of the ‘with’ statement in Python?

A

To simplify exception handling and resource management.

24
Q

Which of the following is NOT a valid variable name in Python? (A) my_var (B) 2nd_var (C) myVar2

25
What is the output of print(0.1 + 0.2 == 0.3)?
False
26
Fill in the blank: A ________ is a collection of unique elements in Python.
set
27
What does the 'map()' function do?
Applies a function to all items in an iterable.
28
True or False: Python uses indentation to define code blocks.
True
29
What is list comprehension?
A concise way to create lists using a single line of code.
30
What does the 'filter()' function do?
Filters items out of an iterable based on a function.
31
Fill in the blank: The ________ module in Python provides functions for working with dates and times.
datetime
32
What is the purpose of the 'return' statement in a function?
To exit the function and return a value.
33
Which of the following is a Python built-in data type? (A) Array (B) List (C) Vector
B
34
What does 'strip()' do when called on a string?
Removes leading and trailing whitespace.
35
What is the output of 2 ** 3?
8
36
True or False: Python is a statically typed language.
False