3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

「[2,3,4,1]」を 「2 3 4 1」 と出力したい場合(python3)

Last updated at Posted at 2018-02-26

HackerRankでたまーにある出力形式で困る

sample outputをみると

2 3 4 1

と書いてある。

何も考えずにリストを普通に出力すると…

コード
print(arr)

出力結果
image.png

いや、もうこれは正解やーーん!!笑

これでは、だめらしいですね…

解決策

コード
print(' '.join(map(str,arr2)))

出力結果
image.png

[追記]
コメントをいただいて、かなり簡単な方法があったので、追記します。

コード

arr = [2, 3, 4, 1]
print(*arr)


> ```text:出力結果
2 3 4 1

めっちゃ簡単ですね!!

3
0
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?