1. 程式人生 > >Python基本資料型別學習-int float bool

Python基本資料型別學習-int float bool

int

int n1=123;
int n2=int(123);
//建立型別為int的物件

float
代表實數,存在精度丟失的問題
保留2位小數位數方法:

a=1
a=("%.2f" % a)
print a 
//結果1.00

bool
python 中布林值使用常量True 和 False來表示;注意大小寫
比較運算子< > == 等返回的型別就是bool型別;布林型別通常在 if 和 while 語句中應用
布林運算子 and or not
注意布林運算的優先順序低於表示式, not a == b 相當於 not (a == b), 若 a == not b 就會有語法錯誤