品易云推流 关闭
文章详情页
文章 > Python常见问题 > Python使用什么划分语句块?

Python使用什么划分语句块?

头像

yang

2020-05-18 10:10:515313浏览 · 0收藏 · 0评论

python以缩进格式来划分句块。在代码前放置空格来缩进语句即可创建语句块,语句块中的每行必须是同样的缩进量。

缩进:Python开发者有意让违反了缩进规则的程序不能通过编译,以此来强制程序员养成良好的编程习惯;

增加缩进表示语句块的开始,而减少缩进则表示语句块的退出。

示例:

this is a line
  this is a line
       this is another block
       continuing the same block
       the last line of this block
  phew,there we escaped the inner block

但是在Python中,冒号(:)用来标识语句块的开始,块中的每一个语句都是缩进的(缩进量相同)。

更多Python知识请关注Python自学网

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图