?
What will be the output of the following Python function?
What will be the output of the following Python function?
any([2>8, 4>2, 1>2])
any([2>8, 4>2, 1>2])
Answer & Solution
Correct Answer:
Option
B
The any() function in Python returns True if at least one element of the iterable is true, otherwise it returns False.
In the provided code, the list [2>8, 4>2, 1>2] contains three boolean expressions:
2>8 evaluates to False.
4>2 evaluates to True.
1>2 evaluates to False.
Since at least one of the expressions (4>2) is true, the any() function returns True.
In the provided code, the list [2>8, 4>2, 1>2] contains three boolean expressions:
2>8 evaluates to False.
4>2 evaluates to True.
1>2 evaluates to False.
Since at least one of the expressions (4>2) is true, the any() function returns True.
Join the Discussion
Login to post a comment or share your explanation.
Login