nerdexam
Python_Institute

PCEP-30-02 · Question #86

What is the data type of x, y, z after executing the following snippet? ``python x = 23 + 42 y = '23' + '42' z = '23' * 7 ``

The correct answer is D. int, str, str. Option D is correct because Python's + operator on integers performs arithmetic addition (23 + 42 = 65, an int), while + on strings performs concatenation ('23' + '42' = '2342', a str), and ` on a string repeats it ('23' 7 = '23232323232323', still a str). Why the distractors…

Question

What is the data type of x, y, z after executing the following snippet?
x = 23 + 42
y = '23' + '42'
z = '23' * 7

Options

  • Aint, int, int
  • Bx is int, y and z are invalid declarations
  • Cint, str, int
  • Dint, str, str

How the community answered

(30 responses)
  • A
    3% (1)
  • B
    7% (2)
  • C
    10% (3)
  • D
    80% (24)

Explanation

Option D is correct because Python's + operator on integers performs arithmetic addition (23 + 42 = 65, an int), while + on strings performs concatenation ('23' + '42' = '2342', a str), and * on a string repeats it ('23' * 7 = '23232323232323', still a str).

Why the distractors fail:

  • A is wrong because y and z involve string operands, not integers.
  • B is wrong because both y and z are perfectly valid - Python's + and * operators are defined for strings.
  • C is wrong because z is a str, not an int; multiplying a string by a number repeats the string, it doesn't do arithmetic.

Memory tip: Think of Python operators as context-sensitive - they behave according to the types of their operands. If even one operand is a string (quoted), + becomes concatenation and * becomes repetition, and the result stays a str.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice