时间:2021-07-01 10:21:17 帮助过:17人阅读
python以什么划分句块?
python以缩进格式来划分句块。
这里打开编辑器,新建一个py文件作为示范。
推荐:《python教程》
- def happy():
- print("Very Happy!")
- happy()
创建函数的时候,冒号以后需要进行缩进,标记语句块。
- x = 1
- while x < 5:
- print(x)
- x += 1
在用while的时候,冒号以后需要进行缩进,标记语句块。
- x = 1
- if x < 10:
- print("ok")
- else:
- print("not ok")
在用if和else语句的时候,冒号以后需要进行缩进,标记语句块。
如果不用标记语句块,是会报错的。
- def hey():
- x = 1
- while x < 3:
- print("hey")
- x += 1
- if x == 3:
- print("ok")
- hey()
每一次冒号以后都是需要标记语句块,而且要根据格式一层一层标记。
以上就是python以什么划分句块的详细内容,更多请关注Gxlcms其它相关文章!