多语言展示
当前在线:1203今日阅读:2今日分享:38

零基础学python之数据类型number

# python中的基础数据类型# 数值类:int(整数) float(浮点数) bool(布尔) str(字符串:特定情况下也可以看作是容器类型)# 容器类:list(列表,数组) tuple(元组) dict(字典) set(集合)# python中整数类型不区分长短,所有整数都属于int类型# python中浮点数类型不区分精度,所有浮点数都属于float类型
工具/原料
1

python 3.1.6

2

pycharm

方法/步骤
1

a = 412print(a, type(a))  # type(x)查询x对应的值所属类型

2

a = 3.5 * 2print(a, type(a))a = int('5')print(a, type(a))f = 5.4print(f, type(f))

3

f = float('4')print(f, type(f))f = 3.14 + 5.4  # 符点数运算可能存在误差print(f)

4

age = 18height = 180.1s = 'age:%d,height:%.2f' % (age, height)print(s, type(s))

6

# 输入2个整数,求和a, b = input('求和:输入2个整数,用空格隔开:').split()print(int(a) + int(b))

7

a = 6b = 8s = '(a+b)*2'res = eval(s)  # 将字符串的内容作为一个表达式。print(res, type(res))print(eval(input('输入一个式子,计算结果:'))

注意事项

# 号后面的中文表示注释

推荐信息