a="asdfghjkl;‘iuygb" b="小米" c=[‘a‘,‘b‘,‘c‘] d= {‘name‘:1,‘age‘:24}
# len统计字符或元素的个数
>>> print(len(a)) >>> print(a[2]) 16 d >>> print(len(b)) >>> print(b[1]) 2 米 >>> print(len(c)) >>> print(c[2]) 3 c >>> print(len(d)) >>> print(d[‘name‘]) 2 24
# is 和==的区别
# is:判断内存地址是否相等
# ==:判断值是否相等
a = 1 b = 1.0 >>> print(id(a)) >>> print(id(b)) 1459716208 2994709930464 >>> print(a is b) >>> print(a == b) False True
# 1.可变类型:在id不变的情况下,value可以变,则称为可变类型,如列表,字典
# 2. 不可变类型:value一旦改变,id也改变,则称为不可变类型(id变,意味着创建了新的内存空间)
#可变类型 >>> l1 = [1,2,3] >>> print(id(l1)) >>> l1.append(4) >>> print(id(l1)) 1446146289160 1446146289160 >>> info = {‘name‘:‘小明‘, ‘age‘:25} >>> print(id(info)) >>> print(info) 1446145409600 {‘name‘: ‘小明‘, ‘age‘: 25} >>> info[‘name‘] = ‘小刚‘ >>> print(id(info)) >>> print(info) 1446145409600 {‘name‘: ‘小刚‘, ‘age‘: 25} #不可变类型 >>> a=1 >>> print(id(a)) 1459716208 >>> a=2 >>> print(id(a)) 1459716240
原文地址:https://www.cnblogs.com/twoo/p/11648614.html
时间: 2024-10-01 07:56:20