布林值 (bool)

布林值物件,其值為 truefalse

由以下項目傳回

布林值物件由下列函式和方法傳回

布林值方法

bool.to_int()

若為 true 則傳回 1,若為 false 則傳回 0

簽名

int to_int()


bool.to_string()

若布林值為 true 則傳回字串 'true',否則傳回 'false'。您也可以傳遞兩個字串作為位置引數,以指定 true/false 的傳回值。例如,bool.to_string('yes', 'no') 若布林值為 true 則傳回 yes,若為 false 則傳回 no

簽名

# Returns the string `'true'` if the boolean is true or `'false'` otherwise
str to_string(
  str [true_str],    # The string to return when the boolean is `true`
  str [false_str],   # The string to return when the boolean is `false`
)

引數

方法 bool.to_string() 接受下列位置引數

名稱 類型 描述 標籤
true_str 字串 (str)

當布林值為 true 時要傳回的字串

[選用]

預設值 = 'true'

false_str 字串 (str)

字串 (str)

[選用]

當布林值為 false 時要傳回的字串


預設值 = 'false'