• 03 可变类型与不可变类型


    ''''''
    '''
    不可变类型:变量的值修改后内存地址不一样
        数字类型
            int
            float
        字符串类型
            str
        元组类型
            tuple
    可变类型:
        列表类型
            list
        字典类型
            dict
    '''
    #int
    number = 100
    print(id(number))   #1717008960
    number = 111
    print(id(number))   #1717009312
    
    #float
    sal = 1.0
    print(id(sal))  #2115946484240
    sal = 2.0
    print(id(sal))  #2115946484072
    
    #str
    str1 = 'hello python!'
    print(id(str1)) #2115981420080
    str2 = str1.replace('hello','like')
    print(id(str2)) #2115982366320
    
    #可变类型
    #列表
    list1 = [1,2,3]
    list2 = list1
    list1.append(4)
    #list1与list2指向的是同一个内存地址
    print(id(list1))    #2115982366472
    print(id(list2))    #2115982366472
    print(list1)    #[1, 2, 3, 4]
    print(list2)    #[1, 2, 3, 4]
  • 相关阅读:
    正则表达式
    .net打印控件基本用法
    批处理
    dos命令
    网络散点
    华为路由器命令
    用eNSP模拟
    oracle PL/SQL语法基础
    路由
    docker redis shell
  • 原文地址:https://www.cnblogs.com/urassya/p/11083561.html
Copyright © 2020-2023  润新知