Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@sbiewald the point is that I wanted to just set a default value for a function. The real solution is to do this (see image)
-
https://docs.python-guide.org/writi...
Additionally:
https://docs.python.org/3/faq/...
Documentation is our friend. -
@AmyShackles agreed. It just took me a while to figure out why my system that's made up of mostly pure functions returned a different number every time I ran it.
-
@A4Abhiraj so will the original code... But that's expected when a language has no typing.
-
h4xx3r16966yWhy the hell a function carry it's private variables after the execution. In other languages I would expect "a" to be re-declared and re-initiated 😑
-
@h4xx3r Function arguments are evaluated once at runtime - it is the same mutable list.
-
@h4xx3r I think the reasoning is that you shouldn't use a mutable object as a default parameter unless you want to utilize the caching functionality, since default arguments are evaluated when the function is defined, not on every eval.
Related Rants
ARGGHHHH Python!!! why the hell is this a thing... if I specify a default argument, I want it to be a default argument, not get carried over....
rant
wtf
python
bugs