ITPub博客

首页 > IT职业 > IT职场 > python怎么在一行上写代码?

python怎么在一行上写代码?

IT职场 作者:lzg215 时间:2021-09-11 10:15:35 0 删除 编辑

python中可以使用分号“;”来分割代码,使所有代码可以写在同一行:

print "How can i write python in a line? n"; print "You can use ';' follow the sentence. " ; print "Then run the script!"; print; print "Done."

在C、Java等语言的语法中规定,必须以分号作为语句结束的标识。Python也支持分号,同样用于一条语句的结束标识。但在Python中分号的作用已经不像C、Java中那么重要了,Python中的分号可以省略,主要通过换行来识别语句的结束。

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

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/420/viewspace-2833424/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-07-23

  • 博文量
    0
  • 访问量
    754