ProgrammingHardAccenture pattern
What is printed?
What is printed?
print("a-b--c".split("-"))
print("a-b--c".split("-", 1))- A. ['a', 'b', 'c'] ['a', 'b--c']
- B. ['a', 'b', '', 'c'] ['a', 'b--c']
- C. ['a', 'b', '', 'c'] ['a', '-b--c']
- D. ['a', 'b', 'c'] ['a', '-', 'b--c']
Correct answer: B. ['a', 'b', '', 'c'] ['a', 'b--c']
Splitting on the literal '-' with no limit keeps every field between delimiters, including the EMPTY string between the two consecutive dashes, giving ['a','b','','c']. Limiting to 1 split stops after the first dash, giving ['a', 'b--c'].
More Python Programming questions
- What is printed? python d = {"b": 2, "a": 1, "c": 3} print(sorted(d.items())) print(dict(sorted(d.items())))
- What is printed? python from functools import lrucache calls = [] @lrucache(maxsize=None) def f(n): calls.append(n) return n n f(2); f(3)…
- What is printed? python def deco(f): def wrapper(a, k): wrapper.calls += 1 return f(a, k) wrapper.calls = 0 return wrapper @deco def h()…
- What is printed? python def decoratorwithargs(prefix): def actual(f): def wrapper(a, k): return prefix + str(f(a, k)) return wrapper…
- What is printed? python class A: def init(self): self.x = 1 def enter(self): return self def exit(self, a): self.x = 0 return False with…
- What is printed? python class R: @property def x(self): return 5 r = R() try: r.x = 10 except AttributeError: print("AttributeError")