Mutable and immutable objects in python

  • About Python parameter passing in the interview

    1 day ago •  coco 2 comments  •  Python  ,  interview

Look at the code first:

################

Which one of the above two output should be?

The first thing that needs to be clarified here is mutable objects and immutable objects. In python, strings, tuples, and numbers are unchangeable objects, while lists, dicts, etc. are objects that can be modified. When a reference is passed to a function, the function automatically copies a reference, so the first immutable object's reference to the value of a has no half-line relationship with the outside a=1, and the following application is a reference to the object itself, then The output value is naturally 1. Have you got this knowledge point?


Original http://group.jobbole.com/10960/?utm_source=blog.jobbole.com&utm_medium=sidebar-group-topic


Guess you like

Origin blog.csdn.net/huochuangchuang/article/details/49844429
Recommended