zoukankan      html  css  js  c++  java
  • python基础day2-可变类型与不可变类型,2019-6-25

    不可变类型:

    变量的值修改后,内存地址一定不一样。

    其中,包括数字类型:interesting,float

    字符串类型:str

    元组类型:tuple

    可变类型:

    变量的值修改后,但内存地址一样。

    包括列表类型list和

    字典类型dict

    不可变类型
    int
    number = 100print(id(number)) # 1434810944number = 111
    print(id(number)) # 1434811296

    # float
    sal = 1.0
    print(id(sal)) # 2771339842064
    sal = 2.0
    print(id(sal)) # 2771339841896

    str1 = 'hello python!'
    print(id(str1)) # 1975751484528
    str2 = str1.replace('hello', 'like')
    print(id(str2)) # 1975751484400


    可变类型:
    列表

    list1 = [1, 2, 3]

    list2 = list1
    list1.append(4)

    # list1与list2指向的是同一份内存地址
    print(id(list1))
    print(id(list2))
    print(list1)
    print(list2)

    会当凌绝顶,一览众山小
  • 相关阅读:
    [转载]解析用户生命周期价值:LTV
    [整理]VS2013常用插件
    Extjs4 tabpanel 中表单定宽居中
    idea创建ssm项目
    shiro框架的学习
    mysql
    springboot
    idea配置
    Spring MVC
    关于web乱码问题
  • 原文地址:https://www.cnblogs.com/leyzzz/p/11086651.html
Copyright © 2011-2022 走看看