iGET

Python Programming - MCQ Practice Questions

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

188 questions | 100% Free

Q.1Medium

What will the following code output?

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

Q.2Medium

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

What will the following code output?

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

Q.4Medium

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

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

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

Q.7Medium

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

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

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

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