Python Programming - Loops

Exercise : Loops - General Questions
  • Loops - General Questions
31.
Which of the following statements accurately describes the behavior of the else block in a Python try-except statement?
It is executed when an exception occurs in the try block.
It is executed when the try block completes without any exceptions.
It is executed only if an exception occurs in the except block.
It is executed when the program terminates.
Answer: Option
Explanation:
The else block in a try-except statement is executed when the try block completes without any exceptions.

32.
What is the purpose of the sorted function in Python when used with loops?
Reverses the order of elements in a list.
Sorts the elements in ascending order.
Returns the index and value of each element in a sequence.
Checks for equality of elements in multiple sequences.
Answer: Option
Explanation:
The sorted function in Python is used to sort the elements in ascending order.