LoginSignup
0
0

More than 3 years have passed since last update.

【メモ】Python3で文字列を空白箇所で改行する方法

Last updated at Posted at 2019-09-10

Python3で、空白を含む文字列が与えられた時に、改行して表示する方法をメモします。
いろんな戦略があることが分かりました。

【入力】
文字列1 文字列2

【目指す出力】
文字列1
文字列2

【コード1】replace関数で空白を改行に置換する
s = input()
print(s.replace(' ', '\n')

【コード2】split関数で文字列を分割し、for文の繰り返しを利用して改行する
s = input()
for i in s.split():
print(s)

0
0
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
0
0