ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'abc' print(s * 0 == '', s[5:] == '', s[-1] + s[0])
- A. True False ca
- B. False True ca
- C. True True ac
- D. True True ca
Correct answer: D. True True ca
Repeating a string zero times gives the empty string. Slicing past the end gives the empty string too. s[-1] is c and s[0] is a.
More Python Programming questions
- What is printed? python print(divmod(-9, 2), divmod(9, -2))
- What is printed? python x = [1, 2] x += x x = 2 print(x)
- What is printed? python d = dict(zip('abc', range(3))) print(d.popitem(), d)
- What is printed? python t = (3, 1, 2) print(sorted(t) == list(t), tuple(sorted(t)), t)
- What is printed? python print(max('apple', 'banana', key=len), max([], default=None))
- What is printed? python print([y for x in [1, 2, 3] if (y := x + 1) % 2 == 0])