Python bool值

时间:2023-12-05 23:08:32
a = 10
print(type(a)) #<class 'int'>
d = str(a) #把数字转换成str
print(type(d)) #<class 'str'>
#
b = "10"
print(type(b)) #<class 'str'>
c = int(b) # b扔到int() 得到的结果就是一个int
print(type(c)) #<class 'int'> #字符串 => 数字 int()
#数字 => 字符串 str()
#x => y类型 y(x)
#结论一:想把xxx数据转化成yy类型的数据.yy() #把数字转化成bool
#0是False,非零是True
a = 10
print(bool(a)) #T
print(bool(1)) #T
print(bool(0)) #F
print(bool(-1)) #T # 空字符串 表示False
print(bool("哈哈")) #T
print(bool(" ")) #空格是T
print(bool("")) #空字符串是False #结论二: 所有的空都可以表示False
print(bool([])) #F 空列表
print(bool({})) #F 空字典
print(bool(set())) #F 空集合 #None 空,真空
print(bool(None)) while 1:
print("还我钱")