python-模块的导入

import导入模块

如果搜索路径时,没有你想加入的东西,则自己导入

import sys
sys.path
#把自己的东西加入到此路径下,然后import就可以导入
sys.path.append("/home")
重新导入模块

import导入一个文件,只会导入时刻之前的内容,之后修改的都无法导入,

#重新加载模块的内容
from imp import *
reload(test)
循环导入

要避免模块之间循环调用,否则会导致程序奔溃

== is

==:判断值相同,is 指向的地址相同

>>> a = [11,22,33]
>>> b = [11,22,33]
>>> a == b
True
>>> a is b
False
>>> id(a)
4331177736
>>> id(b)
4331177864
>>> c = a
>>> c
[11, 22, 33]
>>> id(c)
4331177736
>>> a is c
True
深拷贝和浅拷贝

浅拷贝:
深拷贝

#浅拷贝
>>> b = a
>>> id(a)
4331177736
>>> id(b)
4331177736
#深拷贝
>>> import copy
>>> c = copy.deepcopy(a)
>>> id(a)
4331177736
>>> id(c)
4331201224
>>> c
[11, 22, 33]
>>> a.append(44)
>>> a
[11, 22, 33, 44]
>>> b
[11, 22, 33, 44]
>>> c
[11, 22, 33]
>>> import copy
>>> a = [1,2,3]
>>> b = [4,5,6]
>>> c = (a,b)
>>> e = copy.deepcopy(c)
>>> a.append(8)
>>> c[0]
[1, 2, 3, 8]
>>> e[0]
[1, 2, 3]
>>> a = [1,2,3]
>>> b = [4,5,6]
>>> c = [a,b]
>>> import copy
>>> e = copy.copy(c)
>>> a.append(9)
>>> c[0]
[1, 2, 3, 9]
>>> e[0]
[1, 2, 3, 9]
>>> id(c)
4322789256
>>> id(e)
4322812424

copy拷贝元组时的特点
使用copy模块的copy功能时,他会根据当前拷贝的数据类型是可变类型还是不可变类型拷贝的功能也因此不一样。

>>> a = [1,2,3]
>>> b = [4,5,6]
>>> c = (a,b)
>>> import copy
>>> e = copy.copy(c)
>>> id(c)
4331141768
>>> id(e)
4331141768
>>> a.append(4)
>>> a
[1, 2, 3, 4]
>>> c[0]
[1, 2, 3, 4]
>>> e[0]
[1, 2, 3, 4]
image.png
位运算

位运算的作用是:快速的实现乘除运算
左移是乘,右移是除
按位与 &:只要有一位是0,则为0
按位或 | :只有0或0时才是0,否则都为1
按位异或 ^ :只要不相同,就是1
取反~:原来的0变1,1变0

推荐阅读更多精彩内容