python的bool函数
Python bool (函数) Python bool () function () )。
bool ) ) functionisusedtoconvertagivenvaluetothebooleanvalue (trueorfalse ) ) ) asperthestandardtruthtestingprocedures.itacceptsavalue (likeaninteger,list,maps,etc ) and converts it into a Boolean value
bool ) )函数用于根据标准真值测试过程将值转换为布尔值(True或False )。 接受整数、列表、映射等值,并将其转换为布尔值。
Some of the examples:
一些示例:
none- converts to false无false falseconvertstofalsefalsefalse zeros (0,0.0,0j ) convertstofalse零) 0,0.0,0j
Syntax:
语法:
(bool([value] ) ) ) ) ) ) ) ) )。
parameter 3360 valueavaluetobeconvertedtothebooleanvalue,it’sanoptionalparameter,ifwedonotpassanyparameterit returns
参数: value-要转换为布尔值的值。 这是可选参数,如果不传递参数,则返回False。
return value : boolabooleanvalue
返回值:布尔值
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
pythoncodetoconvertvaluetothebooleanvalue
Python代码将值转换为布尔值
# pythoncodetodemonstrateexample
# 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 ) )
输出
出口量
val=False
val=True
val=True
val=False
val=True
val=False
val=True
val=False
从3:https://www.include help.com/python/bool-function-with-example.aspx翻译
python的bool函数