python缩进

有人能告诉我什么是缩进吗?

# 回答1


缩进是Python知道什么是"块"的方式.块用于循环、If/Else、函数定义、类等.例如:

选择 | 换行 | 行号
  1. for i in range(5):  # begin for loop block
  2.     print i    # indented (usually 4 spaces, sometimes 1 tab)
  3.  
  4. print "hello"    # not indented, not in the block above it.

这是Python(IMO)最酷的特性之一.没有标签,没有分号,没有括号--只有适量的空格.

标签: python

添加新评论