后浪云Python教程:python怎么在一行上写代码?
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中的分号可以省略,主要通过换行来识别语句的结束。
版权声明:
作者:后浪云
链接:https://www.idc.net/help/183217/
文章版权归作者所有,未经允许请勿转载。
THE END