nerdexam
Python_Institute

PCEP-30-02 · Question #264

Consider the following Python code: ``python name = 'Peter' age = 23 flag = True `` What are the types of the variables name, age and ag?

The correct answer is B. str, int, bool. Option B is correct because Python assigns types based on the literal value used: single or double quotes create a str, a whole number creates an int, and True/False keywords create a bool - giving name → str, age → int, and flag → bool. Option A is wrong because float requires…

Question

Consider the following Python code:
name = 'Peter'
age = 23
flag = True
What are the types of the variables name, age and ag?

Options

  • Aoat, bool, str
  • Bstr, int, bool
  • Cint, bool, char
  • Dstr, int, int

How the community answered

(40 responses)
  • A
    3% (1)
  • B
    80% (32)
  • C
    13% (5)
  • D
    5% (2)

Explanation

Option B is correct because Python assigns types based on the literal value used: single or double quotes create a str, a whole number creates an int, and True/False keywords create a bool - giving name → str, age → int, and flag → bool.

Option A is wrong because float requires a decimal point (e.g., 23.0), and the order of types is also incorrect. Option C is wrong because Python has no char type (unlike C/Java), and True is bool, not int (even though bool is technically a subclass of int, the direct type is bool). Option D is wrong because it classifies flag = True as int - while True == 1 numerically, type(True) returns bool, not int.

Memory tip: Match the literal syntax - quotes → str, bare number → int, True/False (capital first letter) → bool. When in doubt, mentally run type(value) in your head.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice