logo
  • 教程列表
  • SO官方文檔
  • 條件語句
    • 條件表示式(或三元運算子)
    • 如果 elif 和其他人
    • 真值
    • 布林邏輯表示式
    • 其他宣告
    • 使用 cmp 函式獲取兩個物件的比較結果
    • if 語句
    • 測試物件是否為 None 並分配它
    • 使用列表理解進行條件表示式評估
  1. StackOverflow 文件
  2. Python Language 教程
  3. 條件語句
  4. 其他宣告

其他宣告

Created: November-22, 2018

if condition:
    body
else:
    body

只有在前面的條件語句全部計算為 False 時,else 語句才會執行它的主體。

if True:
    print "It is true!"
else:
    print "This won't get printed.."

# Output: It is true!

if False:
    print "This won't get printed.."
else:
    print "It is false!"

# Output: It is false!
  • 使用 cmp 函式獲取兩個物件的比較結果
  • 布林邏輯表示式

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明