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

Question 11

Q439 - Data Types


What is the expected output of the following code?



  • A
  • B
  • C
  • D
Reveal correct answer

Correct answer: B

Explanation

Topics: not boolean

Try it yourself:

Explanation:

The values 23 and 'Peter' will evaluate to True

and the rest will evaluate to False

The not turns everything around.

The values that become False in Python are the following:


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

A. The 'not' operator in Python returns the boolean opposite of the operand. In this code snippet, 'not 0' evaluates to True because 0 is considered False in Python, so the opposite is True. 'not 23' evaluates to False because 23 is considered True, so the opposite is False. 'not '' ' evaluates to True because an empty string is considered False, so the opposite is True. 'not 'Peter' ' evaluates to False because a non-empty string is considered True, so the opposite is False. 'not None' evaluates to True because None is considered False, so the opposite is True.

B. The 'not' operator in Python returns the boolean opposite of the operand. In this code snippet, 'not 0' evaluates to True because 0 is considered False in Python, so the opposite is True. 'not 23' evaluates to False because 23 is considered True, so the opposite is False. 'not '' ' evaluates to True because an empty string is considered False, so the opposite is True. 'not 'Peter' ' evaluates to False because a non-empty string is considered True, so the opposite is False. 'not None' evaluates to True because None is considered False, so the opposite is True.

C. The 'not' operator in Python returns the boolean opposite of the operand. In this code snippet, 'not 0' evaluates to True because 0 is considered False in Python, so the opposite is True. 'not 23' evaluates to False because 23 is considered True, so the opposite is False. 'not '' ' evaluates to True because an empty string is considered False, so the opposite is True. 'not 'Peter' ' evaluates to False because a non-empty string is considered True, so the opposite is False. 'not None' evaluates to True because None is considered False, so the opposite is True.

D. The 'not' operator in Python returns the boolean opposite of the operand. In this code snippet, 'not 0' evaluates to True because 0 is considered False in Python, so the opposite is True. 'not 23' evaluates to False because 23 is considered True, so the opposite is False. 'not '' ' evaluates to True because an empty string is considered False, so the opposite is True. 'not 'Peter' ' evaluates to False because a non-empty string is considered True, so the opposite is False. 'not None' evaluates to True because None is considered False, so the opposite is True.

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