iGET

Python Programming - MCQ Practice Questions

Core Python MCQs — syntax, data types, OOP, libraries for placements & IT exams.

188 questions | 100% Free

Q.161Medium

Which of the following Python data structures does NOT allow duplicate elements?

Q.162Medium

What will be the output of the following code?

```python
stack = []
stack.append(10)
stack.append(20)
stack.append(30)
stack.pop()
print(stack)
```

Q.163Medium

What is the key difference between a Python list and a tuple?

Q.164Medium

What will be the output of the following code?

```python
from collections import deque
dq = deque([1, 2, 3])
dq.appendleft(0)
dq.append(4)
print(list(dq))
```

Q.165Medium

Which of the following is the correct way to merge two dictionaries d1 and d2 in Python 3.9 and above, where d2's values take priority for common keys?

Q.166Medium

What will be the output of the following code?

```python
my_set = {3, 1, 4, 1, 5, 9, 2, 6, 5}
print(len(my_set))
```

Q.167Medium

What will be the output of the following code?

```python
from collections import Counter
words = ['apple', 'banana', 'apple', 'cherry', 'banana', 'apple']
c = Counter(words)
print(c.most_common(2))
```

Q.168Medium

What will be the output of the following code?

```python
my_list = [1, 2, 3, 4, 5]
print(my_list[1:4])
print(my_list[::-1])
```

Q.169Medium

What will the following code output?

```python
import numpy as np
a = np.array([1, 2, 3, 4, 5])
print(a[a > 2])
```

Q.170Medium

Which NumPy function is used to compute the dot product of two 1-D arrays `a = np.array([1, 2, 3])` and `b = np.array([4, 5, 6])`?

Q.171Medium

What will the following code output?

```python
import numpy as np
a = np.arange(12).reshape(3, 4)
print(a.shape)
```

Q.172Medium

What is the output of the following code?

```python
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
print(df['A'].sum())
```

Q.173Medium

What will the following code output?

```python
import pandas as pd
df = pd.DataFrame({'X': [10, 20, 30, 40], 'Y': [1, 2, 3, 4]})
print(df.iloc[1:3, 0])
```

Q.174Medium

Which of the following correctly creates a NumPy array of shape `(3, 3)` filled with zeros of integer data type?

Q.175Medium

What is the output of the following code?

```python
import pandas as pd
df = pd.DataFrame({'A': [1, None, 3], 'B': [4, 5, None]})
print(df.isnull().sum())
```

Q.176Medium

What will the following NumPy code output?

```python
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6], [7, 8]])
print(np.matmul(a, b))
```

Q.177Medium

What does the following Pandas code do?

```python
import pandas as pd
df = pd.DataFrame({'City': ['Delhi', 'Mumbai', 'Delhi', 'Chennai'],
'Sales': [100, 200, 150, 300]})
result = df.groupby('City')['Sales'].mean()
print(result)
```

Q.178Medium

What will the following code output?

```python
import numpy as np
a = np.array([1, 2, 3])
b = np.array([10, 20, 30])
print(np.concatenate((a, b)))
print(np.stack((a, b)).shape)
```

Q.179Medium

What is the time complexity of the binary search algorithm implemented on a sorted list in Python?

Q.180Medium

What will be the output of the following code implementing bubble sort?

```python
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr

print(bubble_sort([64, 34, 25, 12, 22]))
```