ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(18 // 4 if False else 'na', 'na' * 2 + 'ba')
  1. A. nana ba
  2. B. na nanaba
  3. C. na naba
  4. D. nanaba na

Correct answer: B. na nanaba

The conditional expression is False, so the first value is the string na. Multiplication binds tighter than +, so 'na' * 2 + 'ba' is nanaba, and the two values are printed separated by a space.

More Python Programming questions

Exams that ask this topic