首页 > 其他分享 >条件控制语句

条件控制语句

时间:2023-01-20 11:34:18浏览次数:57  
标签:语句 控制 elif ... Please else 条件 print

if 语句包含零个或多个 elif 子句,及可选的 else 子句。关键字 ‘elif‘ 是 ‘else if’ 的缩写,适用于避免过多的缩进。可以把 ifelifelif … 序列看作是其他语言中 switchcase 语句的替代品。

  1. >>> x = int(input("Please enter an integer: "))
  2. Please enter an integer: 42
  3. >>> if x < 0:
  4. ... x = 0
  5. ... print('Negative changed to zero')
  6. ... elif x == 0:
  7. ... print('Zero')
  8. ... elif x == 1:
  9. ... print('Single')
  10. ... else:
  11. ... print('More')
  12. ...
  13. More

标签:语句,控制,elif,...,Please,else,条件,print
From: https://www.cnblogs.com/yuyuboy/p/17062596.html

相关文章