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 124 views
2 answers 200 views
1 answer 119 views
1 answer 120 views
1 answer 104 views
...