首页 > IT职业 > IT职场 > 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中的分号可以省略,主要通过换行来识别语句的结束。
更多Python知识请关注Python自学网
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/420/viewspace-2833424/ ,如需转载,请注明出处,否则将追究法律责任。