How to use default parameters to a function that point to the same object in Python

1 Answer

0 votes
def func(arg=[]):
    arg.append("python")
    print(arg)

func()
func()
func()
func()


'''
run:

['python']
['python', 'python']
['python', 'python', 'python']
['python', 'python', 'python', 'python']
 
'''

 



answered Jul 24, 2019 by avibootz

Related questions

1 answer 115 views
2 answers 190 views
1 answer 109 views
1 answer 113 views
1 answer 97 views
...