标签:内存地址 知识点 put gbk str code alt 知识 python
‘‘‘ python2 python3 ‘‘‘ #python2 print() print ‘abc‘ range() xrange() 生成器 raw_input() #python3 print(‘abc‘) range() input() # = 赋值 == 比较值是否相等 is 比较,比较的是内存地址 id(内容) li1 = [1,2,3] li2 = li1 li3 = li2 print(id(li1),id(li2))
>>> li1 = [1,2,3]
>>> li2 = li1
>>> li3 = li2
>>> print(id(li1),id(li2))
6120008 6120008
>>> li3 = 3
>>> print(id(li1),id(li2))
6120008 6120008
>>> print(li2)
[1, 2, 3]
>>> print(li3)
3
>>> print(id(li1),id(li3))
6120008 8791266881344
>>> li2 = 5
>>> li1
[1, 2, 3]
>>> print(id(li1),id(li2))
6120008 8791266881408
>>>
#数字,字符串 小数据池 #数字的范围 -5 -- 256 #字符串:1,不能有特殊字符 # 2,s*20 还是同一个地址,s*21以后都是两个地址 #自己试试 i1 = 6 i2 = 6 print(id(i1),id(i2)) # 8791266881440 8791266881440 共用一个地址 i1 = 300 i2 = 300 print(id(i1),id(i2)) # 6338640 5916688 不共用 s1 = ‘alex‘
s2 = ‘alex‘
print(si is s2) #True
s1 = ‘@alex‘
s2 = ‘@alex‘
print(si is s2) #False
#剩下的 list dict tuple set l1 = [1,] l2 = [1,] print(l1 is l2) #False s = ‘alex‘ s1 = b‘alex‘ print(s,type(s)) print(s1,type(s1))
s = ‘中国‘ print(s,type(s)) s1 = b‘中国‘ print(s1,type(s1))
s1 = ‘alex‘ # encode 编码,如何将str --> bytes, () s11 = s1.encode(‘utf-8‘) s11 = s1.encode(‘gbk‘) print(s11) s2 = ‘中国‘ s22 = s2.encode(‘utf-8‘) s22 = s2.encode(‘gbk‘) print(s22)
标签:内存地址 知识点 put gbk str code alt 知识 python
原文地址:https://www.cnblogs.com/LXL616/p/10636584.html