Python and data for quants
What happens with def f(x, acc=[]): acc.append(x); return acc?
FoundationMultiple choice
What happens with def f(x, acc=[]): acc.append(x); return acc?
- AThe same list is shared across every call, so results accumulate
- BA fresh empty list is created on each call
- CIt raises a syntax error
- DThe behaviour depends on the Python version
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
Report an issue with this question
Learn the method
Of the kind reported at
Optiver, IMC Trading, Citadel Securities, Hudson River Trading, Jump Trading
More python and data for quants questions
- After a = [[0] * 3] * 3 and a[0][0] = 1, what is sum(map(sum, a))?Applied · Premium
- What does round(2.5) return in Python 3?Applied · Premium
- What is sum([i * j for i in range(3) for j in range(3) if i != j])?Foundation · Premium
- What does -7 // 2 evaluate to in Python?Foundation · Premium
- After g = (x for x in range(3)) and list(g), what is len(list(g))?Foundation · Premium
- When should you compare with is rather than == in Python?Foundation · Premium