KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
#!/usr/bin/env python3.2 def f1(a, l=[]): l.append(a) return(l) print(f1(1)) print(f1(1)) print(f1(1)) def f2(a, b=1): b = b + 1 return(a+b) print(f2(1)) print(f2(1)) print(f2(1)) In f1 the argument l has a default value assignment, and it is only evaluated once, so the three print output 1, 2, and 3. Why f2 doesn't do the similar? Conclusion: To make what I learned easier to navigate for future readers of this thread, I summarize as the following: I found this nice tutorial on the topic. I made some simple example programs to compare the difference between mutation , rebinding , copying value , and assignment operator .
Tags (comma-separated)
Save Edits
Cancel