ProgrammingModerateAccenture · Capgemini pattern
What is printed?
What is printed?
s = " Hello, World "
print(s.strip().lower().split(","), s.count("l"), s.find("z"), "-".join("abc"))- A. ['hello', 'world'] 3 -1 a-b-c
- B. ['hello', ' world'] 3 None a-b-c
- C. ['hello', ' world'] 2 -1 abc
- D. ['hello', ' world'] 3 -1 a-b-c
Correct answer: D. ['hello', ' world'] 3 -1 a-b-c
strip removes outer spaces, but split(",") keeps the space after the comma, giving ' world'. count is case-sensitive: three lowercase l's. find returns −1 when absent (index would raise ValueError). join puts the separator between the characters.
More Python Programming questions
- What is printed? python def f(args, kw): return len(args), sorted(kw) print(f(1, 2, [3, 4], a=5, {"b": 6}))
- What is printed? python class A: count = 0 def init(self): A.count += 1 self.count = 10 a = A(); b = A() b.count += 5 print(A.count…
- What is printed? python it = iter([1, 2, 3, 4, 5]) pairs = list(zip(it, it)) print(pairs, list(it))
- What is printed? python import copy a = [[1, 2], [3]] b = copy.copy(a) c = copy.deepcopy(a) a[0].append(9) a.append([4]) print(b, c)
- What is printed? python print(bool([]), bool([0]), bool(""), bool(" "), None == False, 0 == False)
- What is printed? python def countcalls(fn): def wrapper(a): wrapper.calls += 1 return fn(a) wrapper.calls = 0 return wrapper @countcalls…