What's ending comma in print function for?

后端 未结 4 1786
小鲜肉
小鲜肉 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:34

    From Python trailing comma after print executes next instruction:

    1. In Python 2.x, a trailing , in a print statement prevents a new line to be emitted.
    2. The standard output is line-buffered. So the "Hi" won't be printed before a new line is emitted.

提交回复
热议问题