为什么在这个 python 代码段中允许使用分号? [英] Why is semicolon allowed in this python snippet?

查看:36
本文介绍了为什么在这个 python 代码段中允许使用分号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 不保证使用分号来结束语句.那么为什么允许这样做(如下)?

Python does not warrant the use of semicolons to end statements. So why is this (below) allowed?

import pdb; pdb.set_trace()

推荐答案

Python 不需要 分号来终止语句.如果您希望将多个语句放在同一行,可以使用分号 来分隔语句.

Python does not require semi-colons to terminate statements. Semi colons can be used to delimit statements if you wish to put multiple statements on the same line.

现在,为什么允许这样做?这是一个简单的设计决策.我不认为 Python 需要这种分号的东西,但有人认为拥有它并将其添加到语言中会很好.

Now, why is this allowed? It's a simple design decision. I don't think Python needs this semi-colon thing, but somebody thought it would be nice to have and added it to the language.

这篇关于为什么在这个 python 代码段中允许使用分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆