ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
s = 'abc' * 2 + 'd'
print(s[::3], 'bcd' in s, s.index('c', 3))- A. adb True 5
- B. aad True 5
- C. aad False 2
- D. aad True 2
Correct answer: B. aad True 5
s is abcabcd, and a step of 3 picks indices 0, 3 and 6, which are a, a and d. The substring bcd is present, and the first c at or after index 3 is at index 5.
More Python Programming questions
- What is printed? python print(range(0, 10, 3) == range(0, 11, 3), range(0, 10, 3)[-1], len(range(1018)))
- What is printed? python s = 'abc' t = s s += 'd' u = list('abc') v = u u += ['d'] print(s, t, u is v, v)
- What is printed? python print(bin(0b1011011).count('1'), (0b1011011).bitcount(), 0b1011011 & (0b1011011 - 1))
- What is printed? python def f(n): c = 0 while n: n &= n - 1 c += 1 return c print(f(255), f(-1 & 0xFF), f(0))
- What is printed? python s = 'abc' print(s[::-1] + s[0], s[1:] + s[:1], s[-1] + s[-2:])
- What is printed? python print(len('é'), len('é'.encode()), len(f'{"é":>3}'), len(str(0.1 + 0.2)))