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

Question 54

Q479 - Operators


Which of the following expressions evaluates to False and raises no exception?


(Select two answers.)


  • A
  • B
  • C
  • D
Reveal correct answers

Correct answers: C, D

Explanation

Topics: in operator not operator escape sequence


Try it yourself/Explanation:


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

A.

The expression ('a' not in 'abc') evaluates to False because the character 'a' is present in the string 'abc'. The outer 'not' operator negates the result of the inner expression, making it True.

B.

The expression

'\n' in """
"""

evaluates to True because the newline character '\n' is found in the triple-quoted string.

C. The expression not 'a' in 'abc' evaluates to False because the character 'a' is found in the string 'abc'. The 'not' operator negates the result, making it False, and no exception is raised during this evaluation.

D. The expression '123' in '1-2-3' evaluates to False because the string '123' is not found as a substring in the string '1-2-3'. This comparison results in False without raising an exception.

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