yanglee
February 19, 2025, 1:19pm
1
Tell us what’s happening:
if 0 == x:
if y == 10:
print("Yes")
为什么这样才能正确输出yes 这里的缩进规范是什么
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0
Challenge Information:
Python for Everybody - Conditional Execution
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
我已经编辑了您的代码以提高可读性。当您在论坛帖子中输入代码块时,请在代码块前面加上一行三个反引号,并在代码块后面加上一行三个反引号,以使其更易于阅读。
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
您还可以使用编辑器中的“预格式化文本”工具(</>
)在文本周围添加反引号。
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
Indentation is part of Python syntax.
In contrast JavaScript uses curly braces to indicate what code to execute as part of an if
statement, and indentation does not matter:
缩进是 Python 语法的一部分。
相比之下,JavaScript 使用花括号来指示作为“if”语句的一部分要执行的代码,并且缩进并不重要:
if this == that {
execute this code
}
code
if this == that {
execute this code
}
code
JS uses the {braces}
to show what’s part of the IF and what isn’t.
Python uses indentation instead of {braces}
JS 使用 {braces}
来显示哪些是 IF 的一部分,哪些不是。
Python 使用缩进而不是 {braces}
if this == that:
execute this code
code
Without it, you cannot tell which code to execute:
如果没有它,你就无法知道要执行哪段代码:
if this == that:
code
code
我希望这有帮助!