How to pass a list to a function and add elements to the (local) list in the function in Python

1 Answer

0 votes
def function(lang):
    lang = lang + ["c", "c#"]
    for l in lang:
        print(l)

languages = ["python", "java", "c++", "php"]
function(languages)
print(languages)


'''
run:

python
java
c++
php
c
c#
['python', 'java', 'c++', 'php']

'''

 



answered Dec 17, 2017 by avibootz

Related questions

3 answers 342 views
1 answer 226 views
1 answer 182 views
2 answers 177 views
2 answers 261 views
...