1 # -*- coding:utf-8 -*- 2 #整数、浮点数、字符串、布尔值、空值None、列表、字典、集合 3 print(type(int('11111'))) 4 print(type(11111111111111111111111)) 5 print(type(11111111111.11111111111111111111)) 6 print(4/2,9/3) 7 8 print(r'''i'am ok "{a} \\''' . format(a = 5)) #r表示不转义看到是啥就是啥 9 # 在计算机内存中,str统一使用Unicode编码,当需要保存到硬盘或者需要传输的时候,就编码为UTF-8编码。 10 print('123文档') 11 print(b'xe4xb8xad'.decode('utf-8').encode('utf-8'))#byte类型的每个字符都只占用一个字节。传输、保存到文件的类型 12 print(b'123xe6x96x87xe6xa1xa3'.decode('utf-8')) 13 print(b'123xe6x96x87xe6xa1xe6x96x87'.decode('utf-8', errors='ignore'))#忽略部分错误 14 print(type('中文')) 15 print(len('中文'))#字节数 6 16 str = 'abc' 17 print(str.replace("a","AB")) 18 print(str) 19 20 21 print(type(True),type(False)) #and or not 22 print(type(None)) 23 list1 = [4,1,2,5,-8] #有序 24 print(type(list1)) 25 print(len(list1)) 26 list1.insert(1,'insert') 27 list1.append('append') 28 print(list1) 29 print(list1.pop()) #append 30 arr = [2,-9,5,1] 31 arr.sort() 32 print(arr) 33 34 dict1 = {'name':'覃佳','age':18} 35 print(type(dict1)) 36 print(dict1['name']) 37 print('name' in dict1) 38 print('sex' in dict1) 39 print(dict1.get('name')) 40 print(dict1.get('sex',-1)) 41 del dict1['name'] 42 print(dict1) 43 print(dict1.pop('age')) 44 print(dict1) 45 46 print(set([5,5,1,1,2,2,3,4]))#唯一、无序 47 48 age = 6 49 if age > 18: 50 print('adult') 51 elif age > 6: 52 print('teenager') 53 else: 54 print('kid') 55 56 sum = 0 57 for i in range(0,101): 58 sum += i 59 print(sum) 60 print(type(range(1,100))) 61 62 sum = 0 63 n = 0 64 while n < 10: 65 n += 1 66 print(n) 67 if n > 7: 68 break 69 if n % 2 == 0: 70 continue 71 sum += n 72 print(n) 73 print("///",sum,n)