Created
January 30, 2021 01:05
-
-
Save vikjam/b5f4323567c0c4d5b630eb4cb476fbc2 to your computer and use it in GitHub Desktop.
Python mutable default arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
l = ["m"] | |
def return_list(lst=l): | |
return(f"lst={lst} and l={l}") | |
l.append("n") | |
print(return_list()) # lst=['m', 'n'] and l=['m', 'n'] | |
print(return_list(lst=l)) # lst=['m', 'n'] and l=['m', 'n'] | |
l = ["n"] | |
print(return_list()) # lst=['m', 'n'] and l=['n'] | |
print(return_list(lst=l)) # lst=['n'] and l=['n'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment