数字 number
整形 int
浮点型 float
bool True(=1) False(=0)
int_num = 10 float_num = 10.1 bool_True = True bool_False = False print(bool_False == 0, bool_True == 1)
Bool类型判断
0、None、空字符串、空列表、空元组、空字典、空集合为False,其他为True
zero_num = 0 None_type = None empty_str = "" empty_list = [] empty_tuple = () empty_dict = {} empty_set = set() print(bool(zero_num)) print(bool(None_type)) print(bool(empty_str)) print(bool(empty_list)) print(bool(empty_tuple)) print(bool(empty_dict)) print(bool(empty_set))
None 是 NoneType类型
None_type = None print(type(None_type))
浮点数参与的运算结果为浮点数
1. 除法结果为浮点数 /
2. 取整 //
print(10.0 / 2) print(10 / 2) print(10.0 // 3) print(10 // 3)
查看数据类型 type()
ten_num = 9 two_num = "0b1" print(type(ten_num), type(two_num))
计算机计量方式 10进制 2进制 8进制 16进制
10进制:0 1 2 ... 9
2进制:0 1
8进制:0 1 2 ... 7
16进制:0 1 ... 9 A ... F
进制表示和转换
10进制 无前缀 int()
2进制 0b bin()
8进制 0o oct()
16进制 0x hex()
ten_num = 9 two_num = "0b1" eight_num = "0o7" sixteen_num = "0xF" print(ten_num, two_num, eight_num, sixteen_num) # 10 进制转其他进制 print(bin(ten_num), oct(ten_num), hex(ten_num)) # 其他进制转10进制 print(int(two_num, base=2), int(eight_num, base=8), int(sixteen_num, base=16))