ProgrammingEasyAccenture · Capgemini pattern
What is printed?
What is printed?
print(bool([]), bool([0]), bool(""), bool(" "), None == False, 0 == False)- A. False False False True False True
- B. False True False False True True
- C. False True False True True True
- D. False True False True False True
Correct answer: D. False True False True False True
Empty containers and strings are falsy; a list holding 0 and a string holding a space are non-empty, hence truthy. None is falsy but not equal to False, while 0 == False is True because bool is a subclass of int.
More Python Programming questions
- What is printed? python def countcalls(fn): def wrapper(a): wrapper.calls += 1 return fn(a) wrapper.calls = 0 return wrapper @countcalls…
- What is printed? python def make(): acc = [] for i in range(3): def f(x, i=i): return x i acc.append(f) acc.append(lambda x: x + i) return…
- What is printed? python class A: def go(self): return ["A"] class B(A): def go(self): return ["B"] + super().go() class C(A): def…
- What is printed? python def inner(): x = yield 1 y = yield x + 1 return x y def outer(): r = yield from inner() yield r yield from…
- What is printed? python def reg(name, seen={}, order=[]): if name not in seen: seen[name] = len(order) order = order + [name] return…
- What is printed? python def bucket(x, w): return x // w, x % w, int(x / w), -(-x // w) print(bucket(-7, 3), bucket(7, -3))