标签:注意 比较操作符 输出 nbsp 变量 进制 其它 判断 默认
>>> a = ‘cheesezh‘ >>> b = ‘cheesezh‘ >>> a == b True
>>> x = y = [4,5,6] >>> z = [4,5,6] >>> x == y True >>> x == z True >>> x is y True >>> x is z False
>>> name = ‘Fiona‘ >>> age = ‘22‘ >>> name + age ‘Fiona22‘ >>> name*5 ‘FionaFionaFionaFionaFiona‘
>>> name = ‘Fiona‘ >>> ‘your name is %s‘% name ‘your name is Fiona‘
还有%d (十进制) 和 %f (默认保留小数点后6位, %.3f 表示保留3位小数位)的方法,只能传入整数和浮点数,%s 是可以传入字符串和数字的
>>> name = ‘Fiona‘ >>> ‘{} is a good girl‘.format(name) ‘Fiona is a good girl‘
% 和 format 属于格式化输出的用法了(https://www.cnblogs.com/fat39/p/7159881.html)
not > and > or 1 and 3 or 4 and 5 out : 3 1 and 0 or 10 and 7 out : 7
# 浅copy 列表、字典都是一样的。以list举例。 l1 = [1,2,3,4] l2 = l1.copy() # id内存地址不一样,创建了两个空间 l1.append(‘barry‘) # 一个改变,copy不改变 print(l1,id(l1)) # [1, 2, 3, 4, ‘barry‘] 41709256 print(l2,id(l2)) # [1, 2, 3, 4] 41708616
l1 = [1,[22,33,44],3,4,] l2 = l1.copy() l1[1].append(‘55‘) print(l1,id(l1),id(l1[1])) #[1, [22, 33, 44, ‘55‘], 3, 4] 35417160 35417800 print(l2,id(l2),id(l2[1])) #[1, [22, 33, 44, ‘55‘], 3, 4] 35417864 35417800
#深copy.deepcopy() import copy # 先引入模块 l1 = [1,[22,33,44],3,4,] l2 = copy.deepcopy(l1) # 改变第一层 l1[0] = 111 print(l1) # [111, [22, 33, 44], 3, 4] print(l2) # [1, [22, 33, 44], 3, 4] # 改变第二层 l1[1].append(‘barry‘) print(l1) # [111, [22, 33, 44, ‘barry‘], 3, 4] print(l2) # [1, [22, 33, 44], 3, 4]
标签:注意 比较操作符 输出 nbsp 变量 进制 其它 判断 默认
原文地址:https://www.cnblogs.com/fiona128/p/9501537.html