ProgrammingModerateInfosys · Accenture · Capgemini pattern
What is printed?
What is printed?
print("a,b,,c".split(","), len("a b c".split()))- A. ['a', 'b', 'c'] 3
- B. ['a', 'b', '', 'c'] 3
- C. ['a', 'b', 'c'] 4
- D. ['a', 'b', '', 'c'] 4
Correct answer: B. ['a', 'b', '', 'c'] 3
split(",") with a given separator keeps the empty field between the two commas. split() with no argument splits on runs of whitespace and drops empty strings, so "a b c" gives 3 parts.
More Python Programming questions
- What is printed? python print(True + True 3, type(True + 1).name)
- What is printed? python a = [1, 2, 3, 4, 5] a[1:3] = [9] a[::2] = [0, 0] print(a)
- What is printed? python d = {} d[1] = 'a' d[1.0] = 'b' d[True] = 'c' print(d)
- What is printed? python x = [1, 2, 3] for i in x: x.remove(i) print(x)
- What is printed? python fs = [lambda: i for i in range(3)] print([f() for f in fs])
- What is printed? python def f(x, lst=[]): lst.append(x) return lst a = f(1) b = f(2, []) c = f(3) print(a, b, c)