python最具特性的即是运用缩进入表白代码块,不须要运用大括号 {} 。
缩进的空格数是可变的,然而同一个代码块的语句必需包括沟通的缩进空格数。实比方下:
范例
if True: print ("True") else: print ("False")
以次代码结果一条龙语句缩进数的空格数不普遍,会引导运转缺点:
范例
if True:
print ("Answer")
print ("True")
else:
print ("Answer")
print ("False") # 缩进不普遍,会引导运转缺点
之上步调因为缩进不普遍,实行后会展示一致以次缺点:
File "test.py", line 6
print ("False") # 缩进不普遍,会引导运转缺点
^
IndentationError: unindent does not match any outer indentation level
多行语句
Python 常常是一条龙写完一条语句,但即使语句很长,咱们不妨运用反斜杠(\)来实行多行语句,比方:
total = item_one + \
item_two + \
item_three
在 [], {}, 或 () 中的多行语句,不须要运用反斜杠(\),比方:
total = ['item_one', 'item_two', 'item_three',
'item_four', 'item_five']
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。