学习Python和其他语言有很大一点的不一样就是 Python中不适用{}来控制类、函数以及其他逻辑判断,是使用缩进来写模块
下面是正确的写法
#coding-utf-8
print("你好 Python")
if True:
print("It's true")
else:
print("It's false")下面是错误的
#coding-utf-8
print("你好 Python")
if True:
print("It's true")
else:
print("It's false")错误提示是
File "/Users/XXXXXXXXXX/SoftSpace/WorkSpace/Python/Test/com/test/Test.py", line 6
print("It's false")
^
IndentationError: expected an indented block
本文介绍了Python语言中独特的缩进语法特点,并通过示例对比了正确与错误的缩进方式,帮助初学者理解如何遵循Python的代码规范。
1155

被折叠的 条评论
为什么被折叠?



