ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
s = 'abcdefgh' print(s[::-2], s[1::3], s[-3:-6:-1], s[::-1][::2])
- A. hfdb beh fed hfdb
- B. hfdb beh def hfdb
- C. hfdb ehe fed hfdb
- D. hgdb beh fed hfdb
Correct answer: A. hfdb beh fed hfdb
s[::-2] takes every second character from the end, s[1::3] takes indices 1, 4, 7, and s[-3:-6:-1] walks backward from index -3 down to -5. Reversing and then taking every second character gives the same result as the first slice.
More Python Programming questions
- What is printed? python print('%05.1f|%x|%o|%e' % (3.14159, 255, 8, 12345.678))
- What is printed? python print(f'{-5:+}', f'{5:+}', f'{3.0:g}', f'{1e6:g}', f'{1e-5:g}', f'{123456789.0:g}')
- What is printed? python print(f'{12345678:,}', f'{0.5:.0%}', f'{2.5:.0f}', f'{3.5:.0f}', f'{-0.4:.0f}')
- What is printed? python print(repr(1e16), repr(1e15 + 0.3), 1e16 == 1016, 1e16 + 1 == 1e16)
- What is printed? python print(10 -2, 10.0 -2, 1000 10, 2 -1 4)
- What is printed? python print(bool(0.0), bool(-0.0), bool(float('nan')), bool(' '), bool('0'), bool(0j))