Python interview Flashcards
Common questions for python positions (36 cards)
What is the output of print(type(5)) in Python?
<class ‘int’>
True or False: Lists in Python are immutable.
False
What keyword is used to define a function in Python?
def
Fill in the blank: In Python, a ________ is a block of code that only runs when it is called.
function
What is the purpose of the ‘self’ parameter in class methods?
To refer to the instance of the class
Which of the following is a mutable data type in Python? (A) Tuple (B) List (C) String
B
What does the ‘len()’ function do?
Returns the length of an object
True or False: A Python dictionary can have duplicate keys.
False
What method would you use to add an item to a list?
.append()
What is the output of the expression 3 * ‘abc’?
‘abcabcabc’
Which symbol is used for comments in Python?
#
What built-in function can be used to convert a string to an integer?
int()
Fill in the blank: A ________ loop is used to iterate over a sequence in Python.
for
True or False: The ‘break’ statement is used to exit a loop in Python.
True
What is the difference between ‘==’ and ‘is’ in Python?
’==’ checks for value equality, ‘is’ checks for identity.
What does the ‘try’ keyword do in Python?
It begins a block of code to handle exceptions.
What will be the output of the following code: print([1, 2, 3] + [4, 5])?
[1, 2, 3, 4, 5]
Fill in the blank: The ________ keyword is used to handle exceptions in Python.
except
Which method would you use to remove an item from a dictionary?
.pop()
What is a lambda function?
A small anonymous function defined with the ‘lambda’ keyword.
What is the output of the expression ‘Hello’.upper()?
‘HELLO’
True or False: Python supports multiple inheritance.
True
What is the purpose of the ‘with’ statement in Python?
To simplify exception handling and resource management.
Which of the following is NOT a valid variable name in Python? (A) my_var (B) 2nd_var (C) myVar2
B