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 118 views
2 answers 192 views
1 answer 115 views
1 answer 116 views
1 answer 100 views
...