What's ending comma in print function for?

后端 未结 4 1796
小鲜肉
小鲜肉 2020-11-27 19:48

This code is from http://docs.python.org/2/tutorial/errors.html#predefined-clean-up-actions

with open(\"myfile.txt\") as f:
    for line in f:
        print          


        
4条回答
  •  甜味超标
    2020-11-27 20:33

    It prevents the print from ending with a newline, allowing you to append a new print to the end of the line.

    Python 3 changes this completely and the trailing comma is no longer accepted. You use the end parameter to change the line ending, setting it to a blank string to get the same effect.

提交回复
热议问题