2014年3月29日 星期六

Python 學習小筆記 (四) - Conditionals & Control Flow (上)

Python 學習小筆記 () - Conditionals & Control Flow ()


1.       比較(關係)運算:都跟C, C++ 相同
Ø   ==   等於
Ø   !=    不等於
Ø   大於
Ø   >=   大於等於
Ø   <     小於
Ø   <=   小於等於

2.       當比較發生時,回傳的是boolean Type (True or False)
注意:True, False開頭是大寫(C++是小寫的true, false)
Ex:
bool_test = 5 != 42
print bool_test à 輸出True

3.       邏輯運算 and, or:比較左右兩邊的boolean值,回傳boolean
PythonC, C++ 很不同。C, C++ 裡面使用 &&, ||
Python直接使用英文andorand就是 &&, or 就是 ||
Ex:
bool_test1 = True or False  à True
bool_test2 = True and False à False
bool_test3 = 4 > 9 or False  à True
bool_test4 = 78 != 4 and 100 < 99à False

4.       邏輯運算 notC, C++ 使用 "!" 代表not
Python直接使用英文not
Ex:
not True à False
not not Falseà False
not 3**4 < 4**3 à True



If you want to use (copy, paste or quote) my original article, please contact me through email (autek.roy@gmail.com). If there is any mistake or comment, please let me know. :D

如要使用(複製貼上或轉載)作者原創文章,請來信跟我聯絡 (autek.roy@gmail.com)。如果有發現任何的錯誤與建議請留言或跟我連絡。 : )

沒有留言:

張貼留言

請留下您的任何想法或建議!
Please leave any thought or comment!