1. 程式人生 > >python基礎-小結一

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))

#數字,字串 小資料池
#數字的範圍 -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 dict tuple set # l1 = [1,] # l2 = [1,] # print(l1 is l2) # 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)