문제

In Python 2.x, I'd write...

for i in range(5):
    print i,

...to get integers from 0 to 4 printed in the same row. How to do that in Python 3.x, since print is a function now?

도움이 되었습니까?

해결책

Use print(x, end = ' '):

From the release notes:

Old: print x,           # Trailing comma suppresses newline  
New: print(x, end=" ")  # Appends a space instead of a newline
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top