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 333 views
1 answer 222 views
1 answer 172 views
2 answers 170 views
2 answers 255 views
...