iGET

Python Programming - MCQ Practice Questions

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

188 questions | 100% Free

Q.101Medium

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

Q.102Medium

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.103Medium

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.104Medium

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.105Medium

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.106Medium

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.107Medium

What will the following code output?

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

Q.108Medium

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.109Medium

What will the following code output?

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

Q.110Medium

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.111Medium

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.112Medium

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

Q.113Medium

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.114Medium

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.115Medium

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.116Medium

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.117Medium

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

Q.118Medium

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]))
```

Q.119Medium

What is the worst-case time complexity of Quick Sort?

Q.120Medium

What will be the output of the following code?

```python
def binary_search(arr, target):
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1

print(binary_search([2, 5, 8, 12, 16, 23], 12))
```