nerdexam
Python_Institute

PCEP-30-02 · Question #266

What is the expected output of the following code? ``python print(type(1J)) ``

The correct answer is D. <type 'complex'>. In Python, the suffix J (or j) after a number creates a complex number literal - specifically the imaginary part - making 1J equivalent to the complex value 0+1j. Option D is correct because type(1J) evaluates to <class 'complex'> (shown as <type 'complex'> in Python 2 style)…

Question

What is the expected output of the following code?
print(type(1J))

Options

  • A<type 'dict'>
  • B<type 'unicode'>
  • C<type 'oat'>
  • D<type 'complex'>

How the community answered

(29 responses)
  • A
    3% (1)
  • B
    7% (2)
  • C
    10% (3)
  • D
    79% (23)

Explanation

In Python, the suffix J (or j) after a number creates a complex number literal - specifically the imaginary part - making 1J equivalent to the complex value 0+1j. Option D is correct because type(1J) evaluates to <class 'complex'> (shown as <type 'complex'> in Python 2 style).

Why the distractors are wrong:

  • A (dict) - dictionaries are created with {} or dict(), not numeric literals.
  • B (unicode) - unicode is a string type; 1J has no quotes around it.
  • C (oat) - float is the floating-point type, and even then 1.0 would produce float, not oat (this choice appears to be a typo/trick).

Memory tip: Think of j as the engineering notation for the imaginary unit (mathematicians use i, engineers use j). Whenever you see a bare number ending in j or J in Python, it's always a complex number - no exceptions.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice