ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = [1, 2, 3, 4] y = x x = x + [5] x.append(6) y.append(9) print(len(x), len(y), y is x)
- A. 5 5 False
- B. 6 5 True
- C. 6 5 False
- D. 6 6 False
Correct answer: C. 6 5 False
x + [5] creates a new list, so x no longer refers to y's list. y is the original list with 9 appended, which has 5 items. x is a new list with 6 items, and the two are not the same object.
More Python Programming questions
- What is printed? python from collections import Counter c = Counter([3, 1, 3, 2, 1, 3]) print(c.mostcommon(1), sorted(c.elements()), c[7])
- What is printed? python from math import comb print(comb(5, 2), comb(5, 7), comb(0, 0), comb(3, 1) comb(3, 1))
- What is printed? python x = 0 total = 0 for i in range(1, 6): if i % 2: continue x += i if x > 4: break else: total = -1 print(x, total)
- What is printed? python def f(n): if n <= 1: return n return f(n - 1) + f(n - 2) print(f(20), f.defaults)
- What is printed? python s = 'abcabc' print(s.index('c'), s.rindex('a'), s.find('bca', 1), s.count('bc', 1, 4))
- What is printed? python nums = [4, 9, 16] print(list(map(pow, nums, [0.5] 3)), [n 0.5 for n in nums])