标签:逗号 cep weight 字符串类型 整型 body def 逻辑 了解
目录
万能捕捉异常公式
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 = 'nick'
name = "nick"
name = '''
nick
nick
'''
name = """
nick
nick
"""
name = "'nick'"
name = '"nick"'
friends_list = ['longzeluola','canglaoshi','qiaobenai','nick']
lis = list('abcd')
friends_tuple = ('longzeluola','canglaoshi','qiaobenai','nick')
tup = tuple('abcd')
nick_info_dict = {
'name':'nick',
'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}
==
一个值 | 多个值 |
---|---|
整型/浮点型/字符串 | 列表/元祖/字典/集合/ |
有序 | 无序 |
---|---|
字符串/列表/元祖 | 字典/集合 |
可变 | 不可变 |
---|---|
列表/字典/集合 | 整型/浮点型/字符串 |
标签:逗号 cep weight 字符串类型 整型 body def 逻辑 了解
原文地址:https://www.cnblogs.com/nickchen121/p/11069996.html