MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What would the following program print to the screen when run?my ____ list = [7, 0, 0, “d", “n", “o", “B"]my ____ list.reverse()for thing in my ____ list:print(thing)
A
700dnoB
B
007Bond
C
Bond007
D
700donB
Explanation: 

Detailed explanation-1: -In Python, a built-in function called reverse() is used to reverse the list. This simple and quick way to reverse a list in Python requires little memory. Syntax: list name. reverse() Here, list name means you have to write the list’s name, which has to be reversed.

Detailed explanation-2: -Definition and Usage The reverse() method reverses the sorting order of the elements.

Detailed explanation-3: -3) Using for loop Another way to reverse the python list without the use of any built-in methods is using loops. Create an empty list to copy the reversed elements. In the for loop, add the iterator as a list element at the beginning with the new list elements. So in that way, the list elements will be reversed.

There is 1 question to complete.