文章目录
前言
Python数据类型如下:
文本类型: str
数字类型: int, float, complex
序列类型: list, tuple, range
映射类型: dict
套装类型: set, frozenset
布尔类型: bool
二进制类型: bytes, bytearray,memoryview
六、Python数据类型
1、使用type()函数
2、设置数据类型
list列表类型:
tuple元祖类型:
complex复数类型
range范围类型
dict字典类型
set集合类型
3、设置特定数据类型
4、练习题
答案:
1、int
2、str
3、float
4、list(列表[])
5、tuple(元祖())
6、dict(字典)
7、bool
七、Python数字
1、整数——int或者integer
2、浮点数——float
包含一位或者多位小数的正数或者负数
x = 35e3
y = 12E4
z = -87.7e100
print(type(x))
print(type(y))
print(type(z))
3、虚数
复数写有j作为需部
4、类型转换
x = 1 # int
y = 2.8 # float
z = 1j # complex
a = float(x)
b = int(y)
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
5、随机数
内置模块random,需要导入此模块
import random
print(random.randrange(1,11))
6、练习题
答案
八、Python指定变量类型
总结
与上一篇的内容存在重复