ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
s = "abc"
print(s * 0, type(s * 0))
  1. A. abc <class 'str'> <class 'str'>
  2. B. <class 'str'>
  3. C. None <class 'NoneType'>
  4. D. TypeError

Correct answer: B. <class 'str'>

Multiplying a string by 0 produces the empty string (still of type str), not an error and not None; print shows an empty string followed by <class 'str'>.

More Python Programming questions

Exams that ask this topic