什么是 Python Whitespace 以及它是如何工作的? [英] What is Python Whitespace and how does it work?
问题描述
我已经在谷歌和这个网站上搜索了一段时间,但我似乎无法找到关于这个主题的直接答案.
I've been searching google and this website for some time now, but I just can't seem to find a straight answer on the subject.
Python 中的空白是什么?我知道这与每行缩进有关,但我不确定如何使用它.它是如何工作的?
What is whitespace in Python? I know it's something to do with indenting with each line, but I'm not sure exactly how to use it. How does it work?
推荐答案
空格用于表示块.在其他语言中,大括号({
和 }
)很常见.当您缩进时,它成为上一行的子行.除了缩进,父级后面还有一个冒号.
Whitespace is used to denote blocks. In other languages curly brackets ({
and }
) are common. When you indent, it becomes a child of the previous line. In addition to the indentation, the parent also has a colon following it.
im_a_parent:
im_a_child:
im_a_grandchild
im_another_child:
im_another_grand_child
在我的脑海里,def
、if
、elif
、else
、try
、except
、finally
、with
、for
、while
、和 class
都是起始块.结束一个块,你简单的outdent,你会有兄弟姐妹.在上面的im_a_child
和im_another_child
是兄弟.
Off the top of my head, def
, if
, elif
, else
, try
, except
, finally
, with
, for
, while
, and class
all start blocks. To end a block, you simple outdent, and you will have siblings. In the above im_a_child
and im_another_child
are siblings.
这篇关于什么是 Python Whitespace 以及它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!