A. try-except B. try-catch C. try-finally D. catch-finally AnswerOption: A
Read More »Python
|
What is the output of the following code?
for i in range(5): if i == 3: continue print(i) A. 0 1 2 B. 0 1 2 4 C. 0 1 2 3 D. 0 1 2 3 4 AnswerOption: B
Read More »What does the continue statement do in a loop?
A. Ends the loop immediately B. Skips the current iteration and moves to the next one C. Restarts the loop from the beginning D. Stops the loop after completing the current iteration AnswerOption: B
Read More »What is the output of the following code?
i = 0 while i < 3: i += 1 print(i) A. 0 B. 1 C. 2 D. 3 AnswerOption: D
Read More »Which statement is used to exit a loop prematurely in Python?
A. exit B. break C. continue D. stop AnswerOption: B
Read More »What is the output of the following code?
for i in range(3): print(i) A. 0 1 2 B. 1 2 3 C. 1 2 3 4 D. 0 1 2 3 AnswerOption: A
Read More »Which of the following is the correct syntax for a for loop in Python?
A. for i in range(5): B. for (i = 0; i < 5; i++): C. foreach i in range(5): D. for i range(5): AnswerOption: A
Read More »What is the output of the following code?
x = 10 if x > 5: print(“Greater”) else: print(“Smaller”) A. Greater B. Smaller C. Error D. None AnswerOption: A
Read More »Which method is used to add a key-value pair to a dictionary?
A. append() B. insert() C. add() D. update() AnswerOption: D
Read More »What is the output of the following code?
my_dict = {‘a’: 1, ‘b’: 2} print(my_dict.get(‘c’, 3)) A. 1 B. 2 C. 3 D. None AnswerOption: C
Read More »Which of the following creates an empty dictionary in Python?
A. {} B. dict() C. [] D. set() AnswerOption: B
Read More »What is the output of the following code?
set1 = {1, 2, 3} set2 = {2, 3, 4} print(set1 & set2) A. {1, 2, 3, 4} B. {2, 3} C. {1, 4} D. {} AnswerOption: B
Read More »How can you remove elements from a list in Python?
A. remove() B. pop() C. del D. All of the above AnswerOption: D
Read More »What is the output of the following code?
my_tuple = (1, 2, 3, 4) print(my_tuple[2]) A. 1 B. 2 C. 3 D. 4 AnswerOption: C
Read More »Which of the following is used to create a tuple in Python?
A. () B. [] C. {} D. AnswerOption: A
Read More »
MCQs | eBooks – Textbook Solutions All types eBook are available
