This is like a Python MCQ article today in this article you will get questions on What will be the output of the following python code this is one of the most popular questions and answers quiz which many developers like to answer.
There will be many What will be the output of the following python code questions and answers which you can answer which will drastically help you to increase your python programming knowledge and logic building skill.
What will be the output of the following python code MCQ
Contents
Now let’s see What will be the output of the following python code MCQ questions and answers try to solve these questions you can check your answers by clicking the show answer button below each question I hope you enjoy this questions.
Want more MCQ questions and answers then you can refer to this articles:
- Machine learning MCQ for beginners and experts.
- HTML MCQ questions and answers for beginners.
- Javascript MCQ questions and answers for beginners.
1. What will be the output of the following python code?
name = 'coder'
print(name)
-
- name
- coder
- throw error
- None of the above
ANSWER: B
OVERVIEW: The variable name is set to coder so it printed coder.
2. What will be the output of the following python code?
name = 'coder'
name = 'programmer'
print(name)
-
- programmer
- coder
- throw error
- None of the above
ANSWER: A
OVERVIEW: The value of the variable get reassigned to a new value.
3. What will be the output of the following python code?
for i in range(10):
i + 1
-
- 2
- 12
- throw error
- None of the above
ANSWER: A
OVERVIEW: The value of the variable get reassigned to a new value.
4. What will be the output of the following python code?
y = 10
for i in range(y):
print(i)
-
- 0,1,2,3,4,5,6,7,8,9
- 10
- throw error
- None of the above
ANSWER: C
OVERVIEW: Yes this will throw a error because int is not iterable
5. What will be the output of the following python for loop?
for k in range(0):
print(k)
-
- -1
- 0
- throw error
- No Output
ANSWER: D
OVERVIEW: range(0) is empty so no output
6. What will be the output of the following python code snippet?
sum = 1 + 1 - 2
print(sum)
-
- -1
- 0
- throw error
- 2
ANSWER: B
OVERVIEW: 1 + 1 is 2 then 2 – 2 is 0
7. What will be the output of the following python code i=1 while true?
i = 1
while True:
if i%0O7 == 0:
break
print(i)
i += 1
-
- 1 2 3 4 5 6
- 1 2 3 4 5 6 7
- throw error
- None of the above
ANSWER: A
OVERVIEW: Control exits the loop when i becomes 7
8. What will be the output of the following python code?
i = '3'
print(int(i) + 2)
-
- 2
- 5
- throw error
- None of the above
ANSWER: B
OVERVIEW: I know that i is a string but we convert it into integer with int() function.
This was a Python MCQ on what will be the output of the following python code. There will be more question updated in this article so if you want to get updated when this article is updated then do join our Telegram Channel – Join Telegram Channel.
Thank you for reading, Have a nice day 🙂