python 2 python 3 python 2print print‘abc‘range() xrange()生成器raw_input() python3print‘abc‘range()input() = 賦值 ==比較值是否相等 is比較,比較的是内存地址 id(内容)
li1 = [1, 2, 3] li2 = li1 li3 = li2 print(id(li1), id(li2))
數字,字符串,小數據池數字的範圍 -5 -- 256字符串:1.不能有特殊字符 2.s*20 還是同一個地址, s*21以後都是兩個地址
i1 = 6 i2 = 6 print(id(i1), id(i2)) i1 = 300 i2 = 300 print(id(i1), id(i2))
剩下的list dic tuple set,都不共用一個id
l1 = [1, ] l2 = [1, ] print(l1 is l2)
str類型是python3(unicode)
byte類型是用來傳輸和儲存(utf-8,gbk)
s = ‘alex‘ s1 = b‘alex‘ print(s, type(s)) print(s1, type(s1)) s = ‘中國‘ s1 = b‘中國‘ print(s, type(s)) print(s1, type(s1))
s1 = ‘alex‘ # encod編碼如何將str ----> bytes, () s11 = s1.encode(‘utf-8‘) s12 = s1.encode(‘gbk‘) print(s11, s12) s1 = ‘中國‘ s11 = s1.encode(‘utf-8‘) s12 = s1.encode(‘gbk‘) print(s11, s12)
原文地址:https://www.cnblogs.com/yvz5414/p/10193649.html
时间: 2024-10-10 10:41:49