ProgrammingEasyAccenture · Capgemini pattern
What is printed?
What is printed?
a = [1, 2, 3]
a += [4]
a = a + [5]
a.extend("67")
print(a)- A. [1, 2, 3, 4, 5, 67]
- B. [1, 2, 3, 4, 5, '67']
- C. [1, 2, 3, 4, 5, '6', '7']
- D. [1, 2, 3, 4, 5, 6, 7]
Correct answer: C. [1, 2, 3, 4, 5, '6', '7']
+= and + with a list add its elements. extend iterates its argument, and iterating the string "67" yields the characters '6' and '7'. append("67") would add one element '67'.
More Python Programming questions
- What is printed? python x = [[0] 3] 2 y = [[0] 3 for in range(2)] x[0][1] = 5 y[0][1] = 5 print(x, y)
- What is printed? python def add(item, bucket=[]): bucket.append(item) return bucket a = add(1) b = add(2) c = add(3, []) print(a, b, c, a…
- What is printed? python fs = [lambda: i i for i in range(4)] gs = [lambda i=i: i i for i in range(4)] print([f() for f in fs], [g() for g…
- What is printed? python s = "abcdefgh" print(s[1:6:2], s[::-3], s[-3:-1], len(s[5:2]))
- What is printed? python def gen(): for i in range(3): x = yield i print("got", x, end="; ") g = gen() print(next(g), end="; ")…
- What is printed? python a = 256; b = 256 c = [1, 2]; d = [1, 2] print(a == b, c == d, c is d, c[:] is c)