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 215 views
2 answers 323 views
1 answer 210 views
1 answer 210 views
1 answer 205 views
...