ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(repr("it's"), repr('say "hi"'), len('\x41\101'), len(r'\n'))- A. "it's" 'say "hi"' 2 1
- B. "it's" 'say "hi"' 3 2
- C. "it's" 'say "hi"' 2 2
- D. "it's" 'say "hi"' 4 2
Correct answer: C. "it's" 'say "hi"' 2 2
repr() uses double quotes when a string contains a single quote and no double quote, and single quotes otherwise. '\x41\101' is two characters (A and A), while the raw string r'\n' keeps the backslash and n, so it is two characters too.
More Python Programming questions
- What is printed? python print(pow(3, -1, 8)) try: print(pow(4, -1, 8)) except ValueError: print('not invertible')
- What is printed? python import math print(math.comb(100, 50) % 1000, 2100 % 9, sum(map(int, str(2100))) % 9)
- What is printed? python print(5e-324 / 2 == 0, 2e-323 > 5e-324, float('1e-400'), 5e-324 / 2 == 0.0)
- What is printed? python import math print(int(-0.5), int(-1.9), math.floor(-1.1), round(-1.5))
- What is printed? python print(7 & -8, 7 | -8, 7 ^ -8, ~7 & 0xFF)
- What is printed? python print(float(' 1000.5 '), float('infinity') > 1e308, float('-nan') != float('-nan'), int(' +0012 '))