#!/usr/bin/python
def fun(la):
    la[0]=-1
def fun2(la):
    la=-1

#a list can be changed
l1=[1,2,3]
fun(l1)
print l1

#error:'tuple' object does not support item assignment
#t1=(4,5,6)
#fun(t1)
#print t1

#will not change
sb=3
fun2(sb)
print sb

#change to a list then succeed
sb2=[3]
fun(sb2)
print sb2

the code also tell the difference betweet list and tuple.

convert between list and tuple:

ta=tuple(la)

la=list(ta)

 ref page1 page2

 

相关文章:

  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2021-09-24
  • 2021-08-22
猜你喜欢
  • 2021-10-02
  • 2021-11-17
  • 2021-08-17
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2021-10-01
相关资源
相似解决方案