Q1. What is the output of the following Python code?
x={1:"X",2:"Y",3:"Z"}
for i,j in x.items():
print(i,j,end=" ")
A. 1 X 2 Y 3 Z
B. 1 2 3
C. X Y Z
D. 1:”X” 2:”Y” 3:”Z”
Ans: A
Q2. What is output of the following Python code?
x = ['ab', 'cd']
for i in x:
i.upper()
print(x)
A. [‘ab’, ‘cd’]
B. [‘AB’, ‘CD’]
C. [None, None]
D. None of Above
Ans: A (list' object has no attribute 'upper')
Q3. What is the output of the following code?
y= ['ab', 'cd']
for i in y:
y.append(i.upper())
print(y)
A. [‘AB’, ‘CD’]
B. [‘ab’, ‘cd’, ‘AB’, ‘CD’]
C. [‘ab’, ‘cd’]
D. None of Above
Ans: D
Q4. What is the output of below Python code?
x = (j for j in range(3))
for j in x:
print(j)
for j in x:
print(j)
A. 0 1 2
B. error
C. 0 1 2 0 1 2
D. All of Above
Ans: A
Expl: We can loop over a generator object only once.
Q5. What is the output of the below Python code?
string = "This is Career Bodh Sansthan"
for i in string.split():
print (i, end=", ")
A. t, h, i, i,s, C,a, r, e,e,r,B,o,d,h,S,a,n,s,t,h,a,n
B. This, is, Career Bodh Sansthan,
C. This, is, Career, Bodh, Sansthan,
D. None of Above
Ans: C
Explanation: Variable i takes the value of one word at a time.
Q6. What is the output of Python program?
i = [0, 1, 2, 3]
for i[0] in i:
print(i[0])
A. 0 1 2 3
B. 0 1 2 2
C. 3 3 3 3
D. None of Above
Ans: A
Q7. What is the output of Python program?
print (0.1 + 0.2 == 0.3)
A. True
B. False
C. Error
D. None of Above
Ans: B
Q8. What is the output of Python program?
print (1 + 2 == 3)
A. True
B. False
C. Error
D. None of Above
Ans: A
Q9. What is the output of Python program?
print (01 + 02 == 03)
A. True
B. False
C. Error
D. Invalid
Ans: D
Q10. Which is the correct operator for power (xy)?
A. x^y
B. x**y
C. x^^y
D. None of Above
Ans: B
Q11. What is the output of the following Python program?
a = 123
for i in a:
print(i)
A. 1 2 3
B. 123
C. Error
D. None of Above
Ans: C (TypeError: 'int' object is not iterable)
.Q12. What is the output of following python program?
a = 1, 2, 3
for i in a:
print(i)
A. 1
2
3
B. 1,2,3
C. Error
D. None of Above
Ans: A
Q13. What is the output of Python code?
sum=0
x=[1,3,6,7]
for i in x:
sum=sum+i
print(sum)
A. 15
B. 17
C. 1367
D. None of Above
Ans: B
Q14. What is the output of following code?
for i in [0, 1, 2, 3]:
for j in [0, 1, 2, 3, 4]:
print('*')
A. 4 times *
B. 5 times *
C. 20 times *
D. 9 times *
Ans: C
Q15. Which statement is not printed when below python code is execute?
for i in 'Python':
if i == 'h':
continue
print('Current Letter : ' + i)
A. Current Letter : P
B. Current Letter : y
C. Current Letter : t
D. Current Letter : h
Ans: D
Q16. What is the purpose of a for loop in Python?
A. To call a function
B. To iterate over a sequence
C. To perform a logical operations
D. To perform arithmetic operations
Ans: B
Comments