ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
s = 'level'
t = ''.join(reversed(s))
print(s == t, s[::-1] is s, s[::-1] == t, s.count('l') * s.count('e'))- A. True True True 4
- B. False False True 4
- C. True False True 4
- D. True False True 2
Correct answer: C. True False True 4
'level' reads the same backwards, so s equals its reverse. s[::-1] builds a new string object, so the identity test is False even though the values match.
More Python Programming questions
- What is printed? python a = 1e308 b = a 10 print(b, -b, b - b if False else 0, b > a, b == float('inf'))
- What is printed? python import math print(math.sqrt(16), math.sqrt(2) 2 == 2, math.isqrt(2) 2 == 2, math.pow(2, 0.5) == 2 0.5)
- What is printed? python print(int(0.1 10) == 1, int(0.7 10), int(4.35 100), round(4.35 100))
- What is printed? python print(len(str(264)), 264 // 1019, 264 % 1019, len(str(264 - 1)))
- What is printed? python print(-7 // 2 2 + -7 % 2 == -7, 7 // -2 -2 + 7 % -2 == 7, -(-7 // 2))
- What is printed? python x = 0b1011 print(bin(x << 3), bin(x >> 1), x << 3 >> 3 == x, bin(~x & 0b1111))