You are on page 1of 4

4– Question of For Loop Python # By- Prabin K Rout

1. What will be the output of the following Python


code? 7. for I in range( -3 ), how many times this loop will
x = 'abcd' run?
for i in range(len(x)):
print(i) a) 0 c) 1
a) a b c d c) 0 1 2 3 b) Infinity d) Error
b) Error d) 1 2 3 4
2. What will be the output of the following Python 8. for I in [ 1,2,3]:, how many times this loop will
code? run?
x = 'abcd'
for i in range(len(x)): a) 0 c) 1
i.upper() b) 2 d)3
print (x)
a. a b c d c) 1 1 2 3 9. for loop in python are work on
b. Error d) none of the mentioned
3. What will be the output of the following Python a) range object b) iterable object
code? b) both of the above d)none of the mentioned
x = 'abcd'
for i in range(len(x)): 10. Which of the following sequences would be
x[i].upper() generated by the given line of code?
print (x) range (10, 0, -5)
a) abcd b) Error
a) ABCD d) none of the mentioned a) 10, 5 c)-5 0 5 10

4. What will be the output of the following Python b) 0, 5, 10 d)10, 5, 0, -5


code? 11. What is the value of variable sum after
x = 'abcd' execution of the following code?
for i in range(len(x)): sum=10
i[x].upper() for number in range (1, 10, 2):
print (x) sum += number
print (sum)
a) abcd c) Error
b) ABCD d) none of the mentioned a) 19 c)35

5. What will be the output of the following Python b) 23 d)45


code? 12. What is the result of the execution of the
x = 'abcd' following code?
for i in range(len(x)): for x in range (2):
x = 'a' for y in range (2):
print(x) print(x, y, sep='')

a) a c) abcd abcd abcd # which colum ?


b) a a a a d) none of the mentioned
0 0 0 sep 00 01
6. Which of the following loop is work on the 1 0 1 sep 01 10
particular range in python? 10 1 0 sep 10 00
a) Recursion c)while loop 11 1 1 sep 11 11
b) do while loop d)for loop

1
By – Prabin K Rout mob:9861693445 fb:facebook.com/prabinlit insta:prabin_k_rout
4– Question of For Loop Python # By- Prabin K Rout

13. What will be the output of the following 18. For loop can work with iterable objects ?
Python list comprehension?
import math True False
[str(round(math.pi)) for i in range (1, 6)] 19. For loop head will execute how many times ?

[‘3’, ‘3’, ‘3’, ‘3’, ‘3’, ‘3’] 1 N


[‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’, ‘3.141582’] 20. What is the limitation of for loop ?
[‘3’, ‘3’, ‘3’, ‘3’, ‘3’]
[‘3.1’, ‘3.14’, ‘3.142’, ‘3.1416’, ‘3.14159’] Finite movement
Step must be same for each iteration
14. What will be the output of the following Only can work with iterable object
Python list comprehension? All of the above
print([if i%2==0: i; else: i+1; for i in range(4)])
21. Range is a predefined class in python3 used as
a) [0, 2, 2, 4] c)[1, 1, 3, 3] data type ?
b) Error d)none of the mentioned
True False
15. What will be the output of the following
Python list comprehension? 22. What is the default step for range object ?
l1=[1,2,3]
l2=[4,5,6] 1 -1
[x*y for x in l1 for y in l2] 0 2

[4, 8, 12, 5, 10, 15, 6, 12, 18] 23. What is the default start for range object ?
[4, 10, 18]
[4, 5, 6, 8, 10, 12, 12, 15, 18] 0 1
[18, 12, 6, 15, 10, 5, 12, 8, 4] -1 2

16. What will be the output of the following 24. Can we provide float value in start, stop and
Python list comprehension? step for range object ?
num_list = [y for y in range(100) if y % 2 == 0 if y % Yes No
5 == 0]
print( num_list ) 25. What is the output of the following?
x = 'abcd'
A list of all even number for i in range(len(x)):
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90] x[i].upper()
Error print (x)
none of the mentioned
abcd ABCD
17. How many times the following python program error none of the mentioned
will execute ? 26. What is the output of the following?
listObj = [ 'a', 'b', 'c'] x = 'abcd'
for data in listObj : for i in x:
listObj . append ( data . upper () ) print(i.upper())

3 0 abcd ABCD
Error Infinite aBCD Error

2
By – Prabin K Rout mob:9861693445 fb:facebook.com/prabinlit insta:prabin_k_rout
4– Question of For Loop Python # By- Prabin K Rout

27. What is the output of the following? 31. What will be the output of the following
d = {0: 'a', 1: 'b', 2: 'c'} Python code?
for x in d.values(): x = (i for i in range(3))
print(x) for i in x:
print(i)
012 abc for i in x:
0 a 1b 2 c none of the mentioned print(i)

28. What is the output of the following? 012 error


for i in range(float('inf')): 012012 none of the mentioned
print (i) 32. What will be the output of the following
Python code?
0.0 0.1 0.2 0.3 … 0123… a = [0, 1, 2, 3]
0.0 1.0 2.0 3.0 … Error i = -2
for i not in a:
29. What will be the output of the following print(i)
Python code? i += 1
for i in range(10):
if i == 5: -3 0
break Error none of the mentioned
else:
print(i) 33. What will be the output of given Python code?
else: str1="hello"
print("Here") c=0
for x in str1:
0 1 2 3 4 Here if(x!="l"):
c=c+1
0 1 2 3 4 5 Here else:
pass
01234 print ( c )

12345 2 0
4 3
30. What will be the output of the following 34. What will be the output of the following
Python code? Python code?
x = (i for i in range(3)) list1 = [3,2,5,6,0,7,9]
for i in x: sum=0
print(i) sum1=0
for elem in list1:
012 if elem %2==0:
sum = sum+elem
error continue
if elem %3==0:
012012 sum1 = sum1+elem
print(sum ,end=' ')
none of the mentioned print(sum1)

89 83

3
By – Prabin K Rout mob:9861693445 fb:facebook.com/prabinlit insta:prabin_k_rout
4– Question of For Loop Python # By- Prabin K Rout

23 8 12
012 None None None None
35. what is the output of following? Error none of the mentioned
for i in [1, 2, 3, 4][ : : -1]:
print ( i ) 40. What will be the output of the following
Python code?
1234 d = {0, 1, 2}
4321 for x in d:
Error print(x)
none of the mentioned
012
36. what is the output of following?
x= ['ab', 'cd'] {0, 1, 2} {0, 1, 2} {0, 1, 2}
for i in x :
i.upper() Error
print ( x )
none of the mentioned
none of the mentioned
[None, None] 41. What will be the output of the following
['AB', 'CD'] Python code?
['ab', 'cd'] d = {0, 1, 2}
for x in d:
37. What will be the output of the following print(d.add(x))
Python code?
x = 123 012
for i in x:
print(i) 012012012…

123 None None None


123
Error none of the mentioned
none of the mentioned
42. What will be the output of the following
38. What will be the output of the following Python code?
Python code? for i in range(0):
d = {0: 'a', 1: 'b', 2: 'c'} print(i)
for i in d:
print(i) 0

012 abc no output

0a1b2c none of the mentioned Error

39. What will be the output of the following none of the mentioned
Python code?
d = {0, 1, 2}
for x in d.values():
print(x)

4
By – Prabin K Rout mob:9861693445 fb:facebook.com/prabinlit insta:prabin_k_rout

You might also like