python中的print默認是換行的,但是在實際應用中經常會遇到不想輸出換行符的情況,以下是兩種解決方案。
1、print后加‘,’
print 'hello world',
2、使用sys.stdout.write('hello world')
但是,這種方法在執行時並不會實時顯示,每次只有在換行時才會把整行內容打印出來,
如果想要實時顯示,可以
sys.stdout.write('hello world') sys.stdout.flush()
python中的print默認是換行的,但是在實際應用中經常會遇到不想輸出換行符的情況,以下是兩種解決方案。
1、print后加‘,’
print 'hello world',
2、使用sys.stdout.write('hello world')
但是,這種方法在執行時並不會實時顯示,每次只有在換行時才會把整行內容打印出來,
如果想要實時顯示,可以
sys.stdout.write('hello world') sys.stdout.flush()
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。