Question-122: When you run below program, then what would happen or printed?

list = [1, 2, 3, 4, 5]

for i in range(len(list) // 2):

    list[i], list[len(list) - i - 1] = list[len(list) - i - 1], list[i]

print(list)

 

  1. [1, 2, 3, 4, 5]
  2. Get all Questions and Answer from here
  3. You need to have paid subscription to access all questions
  4. Thanks for considering Python Certification Material

 

Answer:  C

Exp:

Python Special

  • This is a special way, provided in Python to swap variable.
  • You don’t need to use any third temporary variable.
  • Simple and straight forward.

first = 'John'

second='Mike'

 

print ("Before Swap ", first, second)

 

first, second = second, first

 

print ("After Swap ", first, second)

 

Another way to reverse a list.

Why Dont you prepare for Python Certifications and Interview Questions with 250+ Questions and Answer : Check Here

Real Exam Number of Questions: 70 Questions
Real Exam Pass Score: 70%
Time Allotted: 90 minutes to complete exam