English ver Introduction 失敗 成功 Reference Introduction コマンドラインで次のような表示をさせたい。 apple apple apple apple apple 失敗 次のようなprintを使ったcodeでは失敗する def main () : i = 0 while i< 5 : print( 'apple' ) j = 0 while j < i: print( ' ' ) j = j + 1 i = i + 1 if __name__ == '__main__' : main() 結果は、、、 Printは使うごとに改行してしまうのです。 成功 次のようなcodeを見てください。 import sys def main () : i = 0 while i < 5 : print( 'apple' ) j = 0 while j <= i: sys.stdout.write( ' ' ) j = j + 1 i = i + 1 if __name__ == '__main__' : main() sys.stdout.write は改行を無視してくれます。 結果!! 一つ注意することはsys.stdout.weiteはstrしか受け付けないことです。 Reference https://www.lifewithpython.com/2013/12/python-print-without-.html
This blog is my learning memo. I write post about ML, math, programing, other. Please click slidebar icon to look for post by contents. content name of post written by Japanese is written Japanese. content name of post written by English is written English. Please look at my post to enjoy and learn ML.