大家好,又见面了,我是你们的朋友全栈君。
python中bool函数
Python bool()函数 (Python bool() function)
bool() function is used to convert a given value to the Boolean value (True or False) as per the standard truth testing procedures. It accepts a value (like an integer, list, maps, etc) and converts it into a Boolean value.
bool()函数用于根据标准真值测试过程将给定值转换为布尔值(True或False)。 它接受一个值(如整数,列表,映射等)并将其转换为布尔值。
Some of the examples:
一些例子:
-
None – converts to False
无-转换为False
-
False – converts to False
False –转换为False
-
Zeros (0, 0.0, 0j) – converts to False
零(0,0.0,0j)–转换为False
-
Empty sequences like, (), [], ‘ ‘ – converts to False
空序列,如(),[],”–转换为False
Syntax:
句法:
bool([value])
Parameter: value – a value to be converted to the Boolean value, it’s an optional parameter, if we do not pass any parameter – it returns False.
参数: value-要转换为布尔值的值,它是可选参数,如果我们不传递任何参数,则返回False。
Return value: bool – a Boolean value
返回值: bool-布尔值
Example:
例:
Input:
val = False
print("val = ", bool(val))
val = True
print("val = ", bool(val))
val = 10
print("val = ", bool(val))
val = 0
print("val = ", bool(val))
Output:
val = False
val = True
val = True
val = False
Python code to convert value to the Boolean value
Python代码将值转换为布尔值
# python code to demonstrate example
# of bool() function
val = False
print("val = ", bool(val))
val = True
print("val = ", bool(val))
val = 10
print("val = ", bool(val))
val = 0
print("val = ", bool(val))
val = 10.23
print("val = ", bool(val))
val = 0.0
print("val = ", bool(val))
val = "Hello"
print("val = ", bool(val))
val = []
print("val = ", bool(val))
Output
输出量
val = False
val = True
val = True
val = False
val = True
val = False
val = True
val = False
翻译自: https://www.includehelp.com/python/bool-function-with-example.aspx
python中bool函数
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/135596.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...