From 43582763779f5236778b9569ca806546714c5ed3 Mon Sep 17 00:00:00 2001 From: lkhsss Date: Sun, 29 Jun 2025 19:11:22 +0800 Subject: [PATCH] Obsidian manual commit: 2025-06-29 19:11:22 --- Python/Conditional_Statements.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Python/Conditional_Statements.md diff --git a/Python/Conditional_Statements.md b/Python/Conditional_Statements.md new file mode 100644 index 0000000..0a4a402 --- /dev/null +++ b/Python/Conditional_Statements.md @@ -0,0 +1,28 @@ +# 条件控制语句 + +## if...else +最简单的**条件控制语句**。如果不需要else也可以**省略**。 +```python +x = 10 + +if x < 5: + print("x比5小") +else: + print("x比5大") +``` + +## if...elif...else +多重条件控制语句,仅需加几个`elif` +```python +num = 5 # 假设一个人在公司的等级 +if num == 3: # 判断num的值 + print 'boss' +elif num == 2: + print 'user' +elif num == 1: + print 'worker' +elif num < 0: # 值小于零时输出 + print 'error' +else: + print 'roadman' # 条件均不成立时输出 +``` \ No newline at end of file