python改变形参的值

  1
  2 def ChangeParameter1( count ):
  3     count = 3
  4  
  5 def ChangeParameter2( count ):
  6     count[0] = 3
 
不会改变ct的值,函数调用后还是0
  8 ct = 0
  9 ChangeParameter1( ct )
 10 print ct
   

会改变,是通过list来实现
 12 ct = list()
 13 ct.append( 0 )
 14 ChangeParameter2( ct )
 15 print ct[0]

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

    分享到:

Leave a Reply

Your email address will not be published. Required fields are marked *