In Python, why won't something print without a newline?

后端 未结 6 2329
轮回少年
轮回少年 2020-12-17 15:53
import time
import sys
sys.stdout.write(\"1\")
time.sleep(5)
print(\"2\")

will print \"12\" after 5 seconds

import time
import sys
         


        
6条回答
  •  时光说笑
    2020-12-17 16:14

    Consider that when you type a command into a computer, it doesn't know you're finished until you press ENTER

    Similarly, the newline tells Python you've finished that line.

提交回复
热议问题