标签:并集 logs http ade 默认值 div discard 键值对 逗号
万能捕捉异常公式
try:
# 逻辑代码
1/0
except Exception as e:
print(e)
division by zero
拷贝/浅拷贝/深拷贝都是针对可变类型数据而言的
l1 = ['a','b','c',['d','e','f']]
l2 = l1
l1.append('g')
print(l1) # ['a','b','c',['d','e','f'],'g']
print(l2) # ['a','b','c',['d','e','f'],'g']
如果l2是l1的拷贝对象,则l1内部的任何数据类型的元素变化,则l2内部的元素也会跟着改变,因为可变类型值变id不变
import copy
l1 = ['a','b','c',['d','e','f']]
l2 = copy.copy(l1)
l1.append('g')
print(l1) # ['a','b','c',['d','e','f'],'g']
print(l2) # ['a','b','c',['d','e','f']]
l1[3].append('g')
print(l1) # ['a','b','c',['d','e','f','g'],'g']
print(l2) # ['a','b','c',['d','e','f','g']]
如果l2是l1的浅拷贝对象,则l1内的不可变元素发生了改变,l2不变;如果l1内的可变元素发生了改变,则l2会跟着改变
import copy
l1 = ['a','b','c',['d','e','f']]
l2 = copy.deepcopy(l1)
l1.append('g')
print(l1) # ['a','b','c',['d','e','f'],'g']
print(l2) # ['a','b','c',['d','e','f']]
l1[3].append('g')
print(l1) # ['a','b','c',['d','e','f','g'],'g']
print(l2) # ['a','b','c',['d','e','f']]
如果l2是l1的深拷贝对象,则l1内的不可变元素发生了改变,l2不变;如果l1内的可变元素发生了改变,l2也不会变,即l2永远不会因为l1的变化而变化
age = 18
age = int('18') # 含有字符串不可以
+ - * / % // **
salary = 3.2
salary = float('3.2')
+ - * / % // **
name = 'randy'
name = "randy"
name = '''
randy
randy
'''
name = """
randy
randy
"""
name = "'randy'"
name = '"randy"'
friends_list = ['longzeluola','canglaoshi','qiaobenai','randy']
lis = list('abcd')
friends_tuple = ('longzeluola','canglaoshi','qiaobenai','randy')
tup = tuple('abcd')
randy_info_dict = {
'name':'randy',
'height':180,
'weight':140,
'hobby_list':['read','run','music','fishing','programming','coding','debugging']
}
for k,v in nick_info_dict.items():
print(k,v)
s = set()
s = {1,2,3,4,5,1}
==
1.作用:一般用于判断,除了0/None/空/False自带布尔值为False,其他的数据类型自带布尔值为True
一个值 | 多个值 |
---|---|
整型/浮点型/字符串 | 列表/元祖/字典/集合/ |
有序 | 无序 |
---|---|
字符串/列表/元祖 | 字典/集合 |
可变 | 不可变 |
---|---|
列表/字典/集合 | 整型/浮点型/字符串 |
标签:并集 logs http ade 默认值 div discard 键值对 逗号
原文地址:https://www.cnblogs.com/randysun/p/12238188.html