I used list, def. why li += [100, 200] , and li = li + [100, 200] is different

임현준 immenige2 at gmail.com
Mon Oct 23 12:29:19 EDT 2017


I am a Korean student, and I am a beginner in English and Python.;(

I can't understand about this def

If I want to print 

[1,2,3,4,5]
[1,2,3,4,5,100,200]

I will make code like this, and I can understand code.


def modify(li):
     li += [100,200]

list = [1,2,3,4,5]
print(list)
modify(list)
print(list)


BUT, when I make code like this.

I will make code like this, and I can understand code.


def modify(li):
     li = li + [100,200]

list = [1,2,3,4,5]
print(list)
modify(list)
print(list)



python print

[1,2,3,4,5]
[1,2,3,4,5]

why 'li+= [100,200]'and 'li = li + [100,200]' 's print is different
please help me



More information about the Python-list mailing list