python语言中缩进是强制的吗,为什么Python严格限制缩进?

This question is coming from this Stack Overflow question. Why is Python is designed to use correct indentation either space or tab? In this way, is it purposefully to serve any benefit?

解决方案

Indentation is essential in Python; it replaces curly braces, semi-colons, etc. in C-like syntax.

Consider this code snippet, for example:

def f(x):

if x == 0:

print("x is zero")

print("where am i?")

If it weren't for indentation, we would have no way of indicating what code block the second print statement belongs to. Is it under the if statement, the function f or just by itself in the document?

你可能感兴趣的:(python语言中缩进是强制的吗,为什么Python严格限制缩进?)