Learn Mode

Python Programming and Data Structures Quiz

#1

Which of the following data types is mutable in Python?

List
Explanation

Lists can be modified after creation.

#2

What will be the output of the following code?

```
print(2 + 2 * 3 - 2 / 2)

7
Explanation

Follows PEMDAS rule, resulting in 7.

#3

What is the purpose of the 'pass' statement in Python?

To create an empty code block
Explanation

'pass' serves as a placeholder for future code.

#4

What is the output of the following code?

```
print(10 / 2)

2.0
Explanation

Result of division operation in Python.

#5

Which of the following is not a valid data type in Python?

Array
Explanation

'Array' is not a built-in data type in Python.

#6

Which of the following statements is true regarding Python's 'pass' statement?

It does nothing and acts as a placeholder
Explanation

'pass' is used as a no-operation placeholder.

#7

What is the output of the following code?

```
my_list = [1, 2, 3]
print(my_list[3])

Error
Explanation

Accessing index out of range raises an error.

#8

What is the time complexity of searching for an element in a binary search tree (BST) in the worst-case scenario?

O(log n)
Explanation

Binary search in BST has logarithmic time complexity.

#9

Which of the following sorting algorithms has the worst-case time complexity of O(n^2)?

Bubble Sort
Explanation

Bubble sort has quadratic time complexity.

#10

What will be the output of the following code?

```
def foo(x, y=[]):
y.append(x)
return y

print(foo(1))
print(foo(2))

[1], [1, 2, 2]
Explanation

Default argument is shared across function calls.

#11

What will be the output of the following code?

```
print('hello'.capitalize())

Hello
Explanation

Capitalizes the first letter of the string.

#12

In Python, what is the result of '10' == 10?

False
Explanation

Type mismatch results in False.

#13

What does the 'self' keyword represent in Python class methods?

Current instance of the class
Explanation

'self' refers to the instance on which a method is called.

#14

Which of the following statements is true about Python's garbage collection?

Python uses both reference counting and cyclic garbage collection
Explanation

Python employs multiple strategies for garbage collection.

#15

What is the purpose of the 'yield' keyword in Python?

To suspend and resume the execution of a generator function
Explanation

'yield' generates values lazily, preserving state.

#16

Which of the following statements is true about Python's 'lambda' functions?

They can only have one expression
Explanation

Lambda functions are restricted to single expressions.

#17

What does the 'super()' function do in Python?

It invokes the method of the superclass
Explanation

'super()' calls methods from the superclass.

Test Your Knowledge

Craft your ideal quiz experience by specifying the number of questions and the difficulty level you desire. Dive in and test your knowledge - we have the perfect quiz waiting for you!