ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
a = [1, 2, 3, 4, 5] a[1:3] = [9] * 4 print(a)
- A. [1, 9, 9, 4, 5]
- B. [1, 9, 9, 9, 9, 3, 4, 5]
- C. [1, 9, 9, 9, 9, 4, 5]
- D. [1, 9, 9, 9, 9, 5]
Correct answer: C. [1, 9, 9, 9, 9, 4, 5]
Assigning to a plain slice replaces the slice with any iterable, and the length can grow. Here the two items at indices 1 and 2 are replaced by four 9s.
More Python Programming questions
- What is printed? python print(repr('abc'[5:]), repr('abc'[-10:2]), [1, 2][3:0:-1])
- What is printed? python s = 'banana' print(s.find('an', 2), s.rfind('an'), s.find('x'), s.index('na', 3))
- What is printed? python print('aaaa'.count('aa'), 'aaaa'.replace('aa', 'b'), len('aaaaa'.split('aa')))
- What is printed? python x = 3.14159 print(f"{x:08.3f}|{x:>8.2e}|{42:#x}|{'ab'!r:>6}")
- What is printed? python print(f"{1234567.891:,.2f}", f"{255:b}", f"{-5:+d}")
- What is printed? python print('-'.join(map(str, [1, 2])) 2, ('ab' 3).count('ba'))