1 # coding: utf-8 2 3 a = 3434 4 b = 456787654567876545678765456767687878 5 price = 32.43 6 name = ‘marry‘ 7 8 # 输出数据类型 9 print(type(a)) 10 print(type(b)) 11 print(type(price)) 12 print(type(name)) 13 14 # str转换为int 15 # str中只能是阿拉伯数字,不能含有小数点 16 math_grade = int(input(‘请输入数学成绩:‘)) 17 english_grade = int(input(‘请输入英语成绩:‘)) 18 total = math_grade + english_grade 19 print(‘总成绩为:%s‘ % total) 20 print(type(total)) 21 22 # float转换为int 23 # 只保留小数点前面的 24 f = 43.65 25 i = int(f) 26 print(i) 27 print(type(i)) 28 29 # int和float转换为str 30 f = 23.54 31 i = 343 32 s = str(f) 33 print(s) 34 print(type(s)) 35 s = str(i) 36 print(s) 37 print(type(s)) 38 39 # int和str转换为float 40 i = 89 41 s = ‘789.45‘ 42 f = float(i) 43 print(f) 44 print(type(f)) 45 f = float(s) 46 print(f) 47 print(type(f))