本文共 1974 字,大约阅读时间需要 6 分钟。
取整 double slash //
= math.floor()取余 percentage / modulus operator %
逻辑运算符:
· And: & · Or: | · XOR: ^ 计算过程:将数字换算成二进制后,每一位分别进行逻辑XOR的运算 6 ^ 2 2 = 1 0 6 = 1 1 0 ———— == 1 0 0 =》 4ord() 中间放字符,可以显示该字母的unicode码,如ord(a) = 97
chr(97) = ‘a’, 是ord()的反向
eval("4.05")4.05 # floateval("3 + 4")7 # int
python中copy()函数与list[ : ]使用的就是shallow copy,当original list只有一层结构没有嵌套时,不会有什么问题,对新list的更改并不会改变老list。
但当original list为一个嵌套的结构,里面有其他list作为element时,就会出现问题了。import copy## shallow copyoriginal_list = [1, 2, [3,5], 4] new_list = copy.copy(original_list) # 将new_list中的3 改变为 7 后:The original elements before shallow copying1 2 [3, 5] 4 The original elements after shallow copying1 2 [7, 5] 4 ## deep copyoriginal_list = [1, 2, [3,5], 4] new_list = copy.deepcopy(original_list) # 将new_list中的3 改变为 7 后:The new list of elements after deep copying 1 2 [7, 5] 4 The original elements after deep copying1 2 [3, 5] 4
以下内容是更详细的解释,援引自下面的网址
https://www.geeksforgeeks.org/copy-python-deep-copy-shallow-copy/转载地址:http://zquwi.baihongyu.com/