ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
x = 7
print(f'{x=}', f'{x * 2 = }', f'{"a"!r:>4}')- A. x=7 x * 2 = 14 'a'
- B. x=8 x * 2 = 14 'a'
- C. x=7 x * 2 = 41 'a'
- 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
- What is printed? python import keyword print(keyword.iskeyword('match'), keyword.issoftkeyword('match'), keyword.iskeyword('None')…
- What is printed? python print({'a': 1} | {'a': 2, 'b': 3}, {'a': 1} | {}, dict(a=1) == {'a': 1})
- What is printed? python print(format(1234567.891, ',.2f'), format(0.000123, 'e'), format(12, '>5'), format(3, '03'))
- What is printed? python print((1 + 2j) (3 - 1j), abs(3 + 4j), (1 + 2j).conjugate())
- What is printed? python print(list(zip([1, 2, 3], 'ab')), list(zip('ab', [1, 2, 3], [True])), len(list(zip())))
- What is printed? python try: list(zip([1, 2], [3], strict=True)) except ValueError: print('length mismatch') print(list(zip([1, 2], [3])))