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]

 

posted @ 2019-06-25 16:27  urassya  阅读(101)  评论(0)    收藏  举报