Python中数据类型有哪些种类?
- 内容介绍
- 文章标签
- 相关推荐
本文共计867个文字,预计阅读时间需要4分钟。
Python数据类型+1、数字类型+1.1、整数类型(int)
Python数据类型
1、数字类型
1.1、整型(int)
# coding:utf-8 # Time:2022/6/28 20:57 # Author:Yang Xiaopeng # 整型 a = 1 print(a,type(a))1.2、浮点型(float)
# coding:utf-8 # Time:2022/6/28 20:57 # Author:Yang Xiaopeng # 浮点 a = 1.78 b = int(a) # 强制类型转换 print(a, type(a)) print(b, type(b)) # 1 <class 'int'> 精度丢失1.3、布尔型
# coding:utf-8 # Time:2022/6/28 20:57 # Author:Yang Xiaopeng # 布尔型 只有两个值 True 和 False, 注意首字母大写 a = True b = False print(a, type(a)) # True <class 'bool'> print(b, type(b)) # False <class 'bool'> print(int(a), int(b)) c = 12 d = 0 f = '' print(bool(c), bool(d), bool(f)) # 非空和非零即为True1.4、复数型
- 复数由实数部分和虚数部分构成,可以用a + bj,或者complex(a,b)表示, 复数的实部a和虚部b都是浮点型。
本文共计867个文字,预计阅读时间需要4分钟。
Python数据类型+1、数字类型+1.1、整数类型(int)
Python数据类型
1、数字类型
1.1、整型(int)
# coding:utf-8 # Time:2022/6/28 20:57 # Author:Yang Xiaopeng # 整型 a = 1 print(a,type(a))1.2、浮点型(float)
# coding:utf-8 # Time:2022/6/28 20:57 # Author:Yang Xiaopeng # 浮点 a = 1.78 b = int(a) # 强制类型转换 print(a, type(a)) print(b, type(b)) # 1 <class 'int'> 精度丢失1.3、布尔型
# coding:utf-8 # Time:2022/6/28 20:57 # Author:Yang Xiaopeng # 布尔型 只有两个值 True 和 False, 注意首字母大写 a = True b = False print(a, type(a)) # True <class 'bool'> print(b, type(b)) # False <class 'bool'> print(int(a), int(b)) c = 12 d = 0 f = '' print(bool(c), bool(d), bool(f)) # 非空和非零即为True1.4、复数型
- 复数由实数部分和虚数部分构成,可以用a + bj,或者complex(a,b)表示, 复数的实部a和虚部b都是浮点型。

