In this post, we will see different questions which will test your python basic skills.
Let’s see the Questions:
1)
list1 = [1, 3, 2] print(list1 * 3)
Ans:
[1, 3, 2, 1, 3, 2, 1, 3, 2]
2)
a = [[[1, 2],[3, 4], 5], 6, 7] print(a[0][1][1]) print(a[0: ])
Ans:
4 [[[1, 2], [3, 4], 5], 6, 7]
3)
a, b = [3, 1, 2], [5, 4, 6] print(a + b) print(b + a)
Ans:
[3, 1, 2, 5, 4, 6] [5, 4, 6, 3, 1, 2]
4)
q = [2, 1, 3, 2, 5, 4] q.remove(2) print(q)
Ans:
[1, 3, 2, 5, 4]
5)
g = [12, [35, 6, 7], 4, 3.2] print(len(g)) print(g[-1])
Ans:
4 3.2
6)
a, b = [12, 24, 36], [36, 24, 12] c = b + a print(c)
Ans:
[36, 24, 12, 12, 24, 36]
7)
p = [2, 9, 7, 6, 5, 6, 8] for c in p : print(c)
Ans:
2 9 7 6 5 6 8
8)
p = [2, 9, 7, 6, 5, 6, 8] for c in range(2, 6) : print(p[c])
Ans:
7 6 5 6
9)
p = "Computer" for c in range(2, 6) : print(p[c])
Ans:
m p u t
10)
p = [2, 9, 7, 6, 5, 6, 8] p.reverse() for c in range(2, 6) : print(p[c])
Ans:
5 6 7 9
11)
x = 60 y = 20 print(x ^ y) print(x // y)
Ans:
40 3
12)
x = 100 y = 500 print(x and y)
Ans:
500
13)
a =[25, 95,68, 87, 85, 35, 69, 78, 86, 100, 102, 132, 196] print(len(a)) print(a[3: 10: 2]) print(a[-3: -10: 2]) print(a[-13: 0: 2])
Ans:
13 [87, 35, 78, 100] [] []
14)
a =[25, 95,68, 87, 85, 35, 69, 78, 86, 100, 102, 132, 196] print(a.index(95)) print(a[3: 10: -2]) print(a[3: -4: 2]) print(a[-13: 6: 2])
Ans:
1 [] [87, 35, 78] [25, 68, 85]
15)
a =[25, 95,68, 87, 85, 35, 69, 78, 86, 100, 102, 132, 196] print(a.pop(-2)) print(a[3: 5] + a[-3: ]) print(a[3: -8] * 3) a.append([2, 0]) print(a[-2: ])
Ans:
132 [87, 85, 100, 102, 196] [87, 87, 87] [196, [2, 0]]
16)
b = ['abc', '356', '569', 'xyz'] print(b[2][2]) print(b[: : -1]) print(b.pop(2))
Ans:
9 ['xyz', '569', '356', 'abc'] 569
17)
count = 0 while count < 10 : print("Hello") count += 20
Ans:
Hello
18)
odd = [1, 3, 5] print(( odd + [2, 4, 6])[4])
Ans:
4
19)
odd = [1, 3, 5] print((odd + [12, 14, 16])[4] - (odd + [2, 4, 6])[4])
Ans:
10
20)
x = 10 y = 5 for i in range(x - y * 2) : print("%", i)
Ans:
Nothing Printed
Hope you guys find this practice paper useful.