Small set of data code blocks collection pool

Small data pool: small data pool supports data int str bool

== is id

== determines two values ​​are equal numbers, strings, lists

a=10

b=10

a==b

is a determination that the same memory address

a=10

b=10

print(a is b)

int : -5~256

str:

  1. Alphanumeric any length compliance mechanism residing
  2. When a string of multiplication, a total length of not more than 20
  3. When the multiplication of special symbols can only multiply zero

Block: a file py a function, a module, each line terminal

int str bool

int: -5 ~ + infinity **

str: a string multiplication total length not more than 20

bool: True False

Small pool and data in the same block when the first block of code

Resident mechanism: save memory space, improve efficiency (reduce the destruction of open space and space-consuming)

One type of data collection set in python

Defined method:

s={1,2,3,4,5}

Dictionary is a collection of no value

Collection of natural de-duplication

increase:

delete:

change:

check:

Other operations:


Shallow copy

a=[1,2,3,4,5]b=aa[0]=2print(a)print(b)

a=[1,2,3,4,5]b=a[:]a[0]=2print(a)print(b)

Deep copy

1.深浅拷贝

    赋值:  将多个变量名指向一个同一个内存地址就是赋值

    浅拷贝: 只拷贝第一层元素的地址,只有修改拷贝的数据第一层的时候源数据不受影响,
            给可变数据类型进行添加的时候源数据会受影响
            = 是修改  .append是添加  可变数据类型能够修改和添加,不可变数据类型只能修改

    深拷贝: 不可变数据类型内存地址共用,可变数据类型新开辟一个空间 不管嵌套多深


2.集合
    天然去重
    没有值得字典
    无序,可变
    增:add
    删:remove
    改:先删后加
    查:for

    其他操作:
    - & | ^ > <

3.小数据池
    支持 int,str,bool
      int :-5 ~ 256
      str:字符串乘法时总长度不能超过20

    代码块优先级高于小数据池
    id() 查看内存地址


面试题:
    is是判断两边的内存地址是否相同
    == 判断两边的值是否相同

拉勾,智联,boss -- 注册

Guess you like

Origin www.cnblogs.com/python25/p/11402500.html