|
|
|
|
|
by alextgordon
3826 days ago
|
|
Other languages seem to get it right. Even C++! #include <vector>
static int foo(std::vector<int> x = {}) {
x.push_back(10);
return x.size();
}
int main (int argc, char const *argv[]) {
printf("%d\n", foo()); // 1
printf("%d\n", foo()); // still 1
return 0;
}
def foo(x=[]):
x.append(10)
return len(x)
print(foo()) # 1
print(foo()) # 2? wtf?
|
|
Fortunately Python avoided that bit of silliness.