ios內(nèi)置詞典擴(kuò)充 bool是什么函數(shù)?
bool是什么函數(shù)?Bool是Boolean的縮寫。它只有兩個(gè)值:true和false。bool函數(shù)只有一個(gè)參數(shù),并根據(jù)該參數(shù)的值返回true或false。1. 對數(shù)字使用bool函數(shù)時(shí),0返回fal
bool是什么函數(shù)?
Bool是Boolean的縮寫。它只有兩個(gè)值:true和false。bool函數(shù)只有一個(gè)參數(shù),并根據(jù)該參數(shù)的值返回true或false。
1. 對數(shù)字使用bool函數(shù)時(shí),0返回false,其他值返回true。&Gt&Gt&Gt bool(0)false&Gt&Gt&Gt bool(1)true&Gt&Gt&Gt bool(-1)true&Gt&Gt&Gt&Gt bool(21334)true
2。對字符串使用bool函數(shù)時(shí),對于沒有值的字符串(即none或空字符串),它返回false,否則返回true。&Gt&Gt&Gt bool(“”)false&Gt&Gt&Gt bool(無)false&Gt&Gt&Gt&Gt bool(“ASD”)true&Gt&Gt&Gt bool(“Hello”)true
3。Bool函數(shù)對于空列表、字典和祖先返回false,否則返回true。&Gt&Gt&Gt a=]&Gt&Gt&Gt&Gt bool(a)false&Gt&Gt&Gt&Gt&Gt a.append(1)&Gt&Gt&Gt bool(a)true
4。使用bool函數(shù)確定是否已設(shè)置值。>>> x=raw輸入(“請輸入數(shù)字:”)請輸入數(shù)字:>>> bool(x.strip())False>>> x=raw輸入(“請輸入數(shù)字:”)請輸入數(shù)字:4>>> bool(x.strip())True