Python bool() 函数 Python 内置函数


描述

bool() 函数用于将给定参数转换为布尔类型,如果没有参数,返回 False。

bool 是 int 的子类。

语法

以下是 bool() 方法的语法:

class bool([x])

参数

  • x -- 要进行转换的参数。

返回值

返回 Ture 或 False。


实例

以下展示了使用 bool 函数的实例:

>>>bool() False >>> bool(0) False >>> bool(1) True >>> bool(2) True >>> issubclass(bool, int) # bool 是 int 子类 True

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2021-05-17
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-19
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
相关资源
相似解决方案