Python bool() 函數

Python 內置函數 Python 內置函數


描述

bool() 函數用於將給定參數轉換為布爾類型,如果沒有參數,返回 False。

bool 是 int 的子類。

語法

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

class bool([x])

參數

  • x -- 要進行轉換的參數。

返回值

返回 True 或 False。


實例

以下展示了使用 bool 函數的實例:

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

Python 內置函數 Python 內置函數