WorksheetsML 1 Python
Total questions: 20
Worksheet time: 10mins
Name
Class
Date
1.
Which of the following is a mutable data type in Python?
a)
tuple
b)
string
c)
list
d)
frozenset
2.
What will be the output of the following code?
```python
x = [1, 2, 3]
print(x[1])
```
a)
IndexError
b)
3
c)
2
d)
1
3.
Which of the following methods can be used to add an element to the end of a list?
a)
insert()
b)
extend()
c)
pop()
d)
append()
4.
What will be the output of the following code?
```python
x = (1, 2, 3)
print(x[2])
```
a)
IndexError
b)
2
c)
1
d)
3
5.
Which of the following is an immutable data type in Python?
a)
tuple
b)
list
c)
dictionary
d)
set
6.
How do you create a tuple in Python?
a)
tuple = {}
b)
tuple = ()
c)
tuple = ()()
d)
tuple = []
7.
What is the correct syntax to define a function in Python?
a)
function_name():
b)
create function_name():
c)
def function_name():
d)
function function_name():
8.
What will be the output of the following code?
```python
x = [1, 2, 3]
for i in x:
print(i)
```
a)
1 2 3
b)
3 2 1
c)
3 4 5
d)
2 3 1
9.
What will be the output of the following code?
```python
x = [1, 2, 3]
x.append([4, 5])
print(x)
```
a)
[1, 2, 3, 4, 5]
b)
[1, 2, 3, [4, 5]]
c)
[1, 2, 3]4 5
d)
IndexError
10.
What will be the output of the following code?
```python
x = (1, 2, 3)
print(x + (4, 5))
```
a)
(4, 5)
b)
(1, 2, 3)
c)
(1, 2, 3, (4, 5))
d)
(1, 2, 3, 4, 5)
11.
Which of the following statements is true about Python lists?
a)
Lists are ordered
b)
Lists cannot be nested
c)
Lists cannot store duplicate values
d)
Lists are immutable
12.
What will be the output of the following code?
```python
x = [1, 2, 3]
x[1] = 99
print(x)
```
a)
Error
b)
[99, 2, 3]
c)
[1, 99, 3]
d)
[1, 2, 99]
13.
What is the correct way to define a tuple with one item?
a)
[1]
b)
None of the above
c)
(1,)
d)
(1)
14.
What will be the output of the following code?
```python
x = (1, 2, 3)
print(len(x))
```
a)
Error
b)
1
c)
3
d)
2
15.
What will be the output of the following code?
```python
x = {1, 2, 3, 4, 5}
print(3 in x)
```
a)
None
b)
True
c)
False
d)
Error
16.
What will be the output of the following code?
```python
x = 10
if x > 5:
print('Greater')
else:
print('Smaller')
```
a)
Error
b)
None
c)
Smaller
d)
Greater
17.
What is the default return value of a function in Python if no return statement is given?
a)
None
b)
0
c)
Empty String
d)
Error
18.
What will be the output of the following code?
```python
for i in range(3):
print(i)
```
a)
1 2 3
b)
None
c)
0 1 2
d)
0 1 2 3
19.
How can you create a list with elements 1, 2, 3, 4 in Python?
a)
list = set(1, 2, 3, 4)
b)
list = {1, 2, 3, 4}
c)
list = (1, 2, 3, 4)
d)
list = [1, 2, 3, 4]
20.
What will be the output of the following code?
```python
x = [5, 10, 15]
print(x[0:2])
```
a)
[5, 10, 15]
b)
[5]
c)
[5, 10]
d)
[10, 15]
100 %
