ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
s = 'abc' print(s[::-1] + s[0], s[1:] + s[:1], s[-1] + s[-2:])
- A. cbaa bca cbb
- B. cbaa acb cbc
- C. cbaa bca cbc
- D. cba bca cbc
Correct answer: C. cbaa bca cbc
s[::-1] is cba and s[0] is a, giving cbaa. Rotating left moves a to the end, giving bca, and s[-2:] is bc, so the last value is cbc.
More Python Programming questions
- What is printed? python print(len('é'), len('é'.encode()), len(f'{"é":>3}'), len(str(0.1 + 0.2)))
- What is printed? python print('%-6s|' % 'ab', '%6.2f|' % 3.14159, '%+.1e' % 12345.6789)
- What is printed? python from decimal import Decimal, ROUNDHALFEVEN print(Decimal('2.5').quantize(Decimal('1'), rounding=ROUNDHALFEVEN)…
- What is printed? python x = 'a,b;c' print(x.split(',', 1), x.split(';')[0].split(','), [t for t in x.replace(';', ',').split(',') if t]…
- What is printed? python print(sorted(['10', '9', '100', '8'], key=len), sorted(['10', '9', '100', '8'], key=int))
- What is printed? python from math import isqrt print(isqrt(1030), isqrt(99), isqrt(1030 - 1))