Pythondex
Blog

What Will Be The Output Of The Following Python Code MCQ

Last updated January 31, 2024 by Jarvis Silva

Are you a python developer looking to brush up your python knowledge and skills then you are at the right place today in this article you will find What will be the output of the following python code MCQ?

I have put up this python MCQ for beginners and expert python programmers as you go forward the difficulty of questions will increase, don’t worry if you don’t know some answers you can click the show answer button to see the answer of a question.

Take a note book or open notepad and track how many questions you got correct, You can test this python code snippet in this online python compiler.

1. What will be the output of the following python code?


text = 'Hello world';
print('text')

  1. Hello world
  2. text
  3. ‘text’
  4. none of the above

Show Answer

2. What will be the output of the following python code?


text = 'Hello world';
print(text)

  1. Hello world
  2. text
  3. null
  4. none of the above

Show Answer

3. What will be the output of the following python code?


name = 'Jericho';
newname = 'Jerry';
name = newname;
print(name);

  1. Jericho
  2. Jerry
  3. JerichoJerry
  4. None of the above

Show Answer

4. What will be the output of the following python code?


name = 'Jericho';
print(f"Hello {name}");

  1. Hello {name}
  2. f Hello {name}
  3. Hello Jericho
  4. Throw a error

Show Answer

5. What will be the output of the following python code?


for i in range(10):
    print(i)

  1. 0,1,2,3,4,5,6,7,8,9,10
  2. 0,1,2,3,4,5,6,7,8,9
  3. 1,2,3,4,5,6,7,8,9,10
  4. 1,2,3,4,5,6,7,8,9

Show Answer

6. What will be the output of the following python code for i in range(0) print(i)


for i in range(0):
    print(i)

  1. 0
  2. Infinite
  3. -1
  4. Nothing

Show Answer

7. What will be the output of the following python code?


for i in range(2,10):
    print(i)

  1. 0,1,10
  2. 2,3,4,5,6,7,8,9
  3. 2,4,6,8
  4. 2,4,6,8,10

Show Answer

8. What will be the output of the following python code?


for i in range(2,10,2):
    print(i)

  1. 2,2,2,2,2,2,2,2
  2. 2,3,4,5,6,7,8,9
  3. 2,4,6,8
  4. 2,4,6,8,10

Show Answer

9. What will be the output of the following python code snippet i =1 while true


i = 1
while True:
    if i%0O7 == 0:
        break
    print(i)
    i += 1

  1. 1,2,3,4,5,6
  2. 1,2,3,4,5,6,7
  3. 1
  4. 0

Show Answer

10. What will be the output of the following python code?


result = 10 + 1 - 1
print(result)

  1. 12
  2. 10
  3. 9
  4. 11

Show Answer

11. What will be the output of the following python code snippet 4 + ‘3’


print(4 + '3')

  1. 43
  2. 7
  3. 4’3′
  4. Throws a error

Show Answer

12. What will be the output of the following python code snippet 4 + ‘3’ Using int()


print(4 + int('3'));

  1. 43
  2. 7
  3. 4’3′
  4. Throws a error

Show Answer

13. What will be the output of the following python code b=’12’ print(b*2)


b = '12'
print(b * 2)

  1. 24
  2. 1212
  3. 122
  4. Throws a error

Show Answer

14. What will be the output of the following python code while true?


True = False
while True:
    print(True)
    break

  1. True
  2. False
  3. Nothing
  4. Throws a error

Show Answer

15. What will be the output of the following python code?


num1 = 11
num2 = 22

print(num1 * num2 / num2)

  1. 22
  2. 11
  3. 345
  4. Throws a error

Show Answer

16. What will be the output of the following code snippet?


string = 'Hello world'
print(string.find('hw'))

  1. 0
  2. 1
  3. -1
  4. Throws a error

Show Answer

17. What will be the output of the following python code snippet?


li = [1,2,3,4]
li.append([5,6,7])

print(li)

  1. 1,2,3,4,5,6,7
  2. [1,2,3,4,[5,6,7]]
  3. [1,2,3,4,5,6,7]
  4. Throws a error

Show Answer

18. What will be the output of the following python code snippet?


x = {1,2,3,4}
y = {3,4,5}

print(x.difference(y))

  1. {1,2}
  2. {1,2,3,4,5}
  3. {1,2,3,4,{3,4,5}}
  4. Throws a error

Show Answer

19. What will be the output of the following python code snippet?


def length(a,b):
    return a(b)
    
print(length(len,'python'))

  1. 5
  2. None
  3. 6
  4. Throws a error

Show Answer

20. What will be the output of the following python code snippet?


def func():
    pass

print(type(func()))

  1. <class ‘function’>
  2. <class ‘type’>
  3. <class ‘NoneType’
  4. None of the above

Show Answer

21. What will be the output of the following python code snippet?


Dict = {1:2,3:4,5:6}
Dict.pop(3,5)

print(Dict)

  1. {1:2}
  2. {1:2, 3:4}
  3. {1:2, 5:6}
  4. Error

Show Answer

22. What will be the output of the following python code snippet?


List = [3,2.1,'4']
List.sort()

print(List)

  1. [2.1,2,’4′]
  2. [2.1,3,4]
  3. [2.1,3]
  4. Error

Show Answer

23. What will be the output of the following python code snippet?


s = 0
for i in range(10,1,-1):
    s -= i

print(s)

  1. 55
  2. -55
  3. 54
  4. -54

Show Answer

24. What will be the output of the following python code snippet?


i = o
for i in range(4):
    print(i)

  1. 1,2,3,4
  2. 0,1,2
  3. 0,1,2,3
  4. Error

Show Answer

25. What will be the output of the following python code snippet?


Tuple = (1,2,3)
new_tuple = Tuple,4,5

print(new_tuple)

  1. (1,2,3,4,5)
  2. ((1,2,3),4,5)
  3. 1,2,3,4,5
  4. Error

Show Answer

So how many you got correct you can tweet your score on Twitter and mention @pythondex. If you want more articles and MCQ like this do join our Telegram channel for updates.

I hope this what will be the output of the following python code MCQ helped you to improve your python knowledge you can find more python guides here – View pythondex guides.

Thank you for reading, Have a nice day 🙂