PCAP 31 03 PCAP Certified Associate Python Programmer · Free Practice Question Hard

Question 57

Q282 - Functions


What is the expected output of the following code?



  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: A

Explanation

Topics: lambda def and operator greater than operator


Try it yourself:


Explanation:

The lambda function will return

the Boolean conjunction of its argument and True

The f() function will invoke it

and pass its second parameter as an argument.

1 > 0 is True will be the argument which is passed to the lambda function.

True and True is True

and therefore True is returned by the lambda function

and then by the f() function

and finally printed.


Q282 (Please refer to this number, if you want to write me about this question.)

A. The lambda function lambda x: x and True evaluates to True when x is True, and 1 > 0 is True, so the function f returns True.

B. The function f does not return None in this case. It returns a boolean value based on the condition provided in the lambda function.

C. The lambda function lambda x: x and True evaluates to True when x is True, and 1 > 0 is True, so the function f returns True, not False.

D. The lambda function lambda x: x and True does not evaluate to 0. The function f returns a boolean value based on the condition, not an integer.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need