zoukankan      html  css  js  c++  java
  • day 7 引用

    1.b=a在c语言和python中的区别

     c语言:a=100  a变量里面放的100

                  b = a    b变量里面也放的100

    python :  a=100   内存中有个100    a放的100的内存地址

          b = a      b也放的100的内存地址

      相当于给100那一块内存,贴个便利签

      

           

    2.type查看数据类型,id查看内存地址

        

        

      注意:自动垃圾回收机制!! 多余的内存会回收

    3.可变类型  列表,字典

    不可变类型  数字 字符串 元组

    ####  字符串
    In [1]: a = "hello"
    
    In [2]: a = "world"
    
    In [3]: 
    
    In [3]: a[0]
    Out[3]: 'w'
    
    In [4]: a[0]= "W"
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-4-30f9d655f9db> in <module>()
    ----> 1 a[0]= "W"
    
    TypeError: 'str' object does not support item assignment
    #####  元组
    In [5]: b = (1,2,3)
    
    In [6]: b[0]
    Out[6]: 1
    
    In [7]: b[0] = 111
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-7-3184fba1d024> in <module>()
    ----> 1 b[0] = 111
    
    TypeError: 'tuple' object does not support item assignment

        

    ##### 可变类型  list列表  dict字典
    In [8]: a = [11,22,33]
    
    In [9]: a[0] = 'fff'
    
    In [10]: a
    Out[10]: ['fff', 22, 33]
    ###  不可变类型都可以当做 字典的key
    In [11]: a = {"name":"alex",3.14:"jack"}
    
    In [12]: a = {"name":"alex",3.14:"jack",(1,2,3):"tom"}
    
    In [13]: a = {"name":"alex",3.14:"jack",(1,2,3):"tom",[11,22]:"fjfj"}
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-13-6fdc428d8d83> in <module>()
    ----> 1 a = {"name":"alex",3.14:"jack",(1,2,3):"tom",[11,22]:"fjfj"}
    
    TypeError: unhashable type: 'list'

         

    哈希算法:value值都经过了哈希算法,存在内存的某地方

  • 相关阅读:
    spring boot-17.RabbitMQ
    spring boot-16.使用redis做缓存
    spring boot-15.缓存
    spring boot-14.集成MyBatis
    spring boot-13.数据访问
    docker 安装完mysql 后客户端无法访问
    【python】string functions
    【转】澄清P问题、NP问题、NPC问题
    ubuntu中使用gensim+word2vec[备忘]
    ubuntu熟悉过程中遇到一些小问题记录一下
  • 原文地址:https://www.cnblogs.com/venicid/p/7866002.html
Copyright © 2011-2022 走看看