ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
a = [1, 2, 3] b = a * 2 b[0] = 9 print(a, b)
- A. [1, 2, 3] [9, 2, 3, 1, 2, 3]
- B. [9, 2, 3] [9, 2, 3, 1, 2, 3]
- C. [1, 2, 3] [9, 2, 3]
- D. [1, 2, 3] [9, 9, 3, 1, 2, 3]
Correct answer: A. [1, 2, 3] [9, 2, 3, 1, 2, 3]
Multiplying a list of ints makes a new list with the items repeated, and later item changes do not affect a.
More Python Programming questions
- What is printed? python s = 'xxxy' print(s.rstrip('y'), s.strip('x'), repr(s.lstrip('xy')))
- What is printed? python print('abc' < 'abcd', 'Z' < 'a', '10' < '9')
- What is printed? python i = 0 while (i := i + 1) < 4: pass print(i)
- What is printed? python print(float('nan') < 0, float('inf') > 10 300, -float('inf') < -10 300)
- What is printed? python print(10 309 > float('inf'), end=' ') try: float(10 309) except OverflowError as e: print(e)
- What is printed? python from collections import Counter d = {'a': 1, 'b': 2} v = d.values() d['c'] = 3 print(len(v), list(v))