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

Question 60

Q540 - Operators


What is the data type of x, y, z after executing the following snippet?



  • A

    int, str, int

  • B

    x is int,

    y and z are invalid declarations

  • C

    int, int, int

  • D

    int, str, str

Reveal correct answer

Correct answer: D

Explanation

Topics: addition operator plus operator string concatenation

             multiply operator string concatenation

Try it yourself:

Explanation:

The first one is a normal addition.

The second one is a string concatenation by addition.

The third one is a string concatenation by multiplication.


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

A. The data type of x is an integer because it results from the addition operation of two integers. The data type of y is a string because it results from the concatenation operation of two strings. However, the data type of z is not an integer, it is a string resulting from the repetition operation of a string.

B. The data type of x is an integer because it results from the addition operation of two integers. However, both y and z are valid declarations. y is a string resulting from the concatenation operation of two strings, and z is a string resulting from the repetition operation of a string.

C. The data type of x is an integer because it results from the addition operation of two integers. Both y and z are strings because y results from the concatenation operation of two strings, and z results from the repetition operation of a string.

D. The data type of x is an integer because it results from the addition operation of two integers. The data type of y is a string because it results from the concatenation operation of two strings. The data type of z is also a string because it results from the repetition operation of a string.

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