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)

    会当凌绝顶,一览众山小
  • 相关阅读:
    关于MFC库和CRT库冲突的分析
    C++ Traits技术
    C/C++的参数传递机制
    C++与正态分布
    前端JavaScript
    python 前端 css
    python 前端 html
    MySQL 数据库
    网络编程 生产者消费者模型 GiL

  • 原文地址:https://www.cnblogs.com/leyzzz/p/11086651.html
Copyright © 2011-2022 走看看