• [Python] Understand Mutable vs. Immutable objects in Python


    In this lesson, you will learn what mutable and immutable objects are, and the difference between them. This understanding will help you determine when objects can be modified in place, and when new objects must be created.

    List is mutable, which means everytime it returns the same id whether or not you have changed it:

    foo = []
    id(foo) // same
    foo.append(3)
    id(foo) // same

    Immtuable such as string:

    str = "Hello"
    id(str) // not the same
    str = "World"
    id(str) // not the same
  • 相关阅读:
    HDU
    HDU
    HDU
    HDU
    西电网络赛
    西电网络赛
    西电网络赛
    西电网络赛
    西电网络赛
    西电网络赛
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8012188.html
Copyright © 2020-2023  润新知