ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
x = 7
print(f'{x=}', f'{x * 2 = }', f'{"a"!r:>4}')
  1. A. x=7 x * 2 = 14 'a'
  2. B. x=8 x * 2 = 14 'a'
  3. C. x=7 x * 2 = 41 'a'
  4. D. x=7 x * 2 = 12 'a'

Correct answer: A. x=7 x * 2 = 14 'a'

The = specifier in an f-string prints the expression text, an equals sign and the repr of the value, so x=7 and x * 2 = 14 come out as written. The !r:>4 part shows 'a' with its quotes, right-aligned in four columns.

More Python Programming questions

Exams that ask this topic