LoginSignup
5
1

More than 1 year has passed since last update.

身も蓋も無えprint(end="Hello, world")

Last updated at Posted at 2023-04-03

こんにちは

Pythonを使っていて、print関数で改行させたくない場合、

print("Hello, world", end="")

こうすることで目的を達成できます。これは、文字列の末尾につけるend引数のデフォルト値が改行であり、それを空文字列で置き換えることによって改行を防げるという仕組みです。

ちょっと待ってください

ところで、文末のendは1文字である必要はなく、文字列を受け取ります。つまり

print(end="Hello, world")

でいいんですね。

終わりに

print(end="身も蓋も無え!\n")

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1