6
2

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.

FizzBuzzAdvent Calendar 2017

Day 17

PythonでワンライナーFizzBuzz

Last updated at Posted at 2017-12-16

python -c 'for i in range(1,101):print(["","Fizz"][i%3<1]+["","Buzz"][i%5<1]or str(i))'

これだけ。

False, True0, 1と評価されることを利用した配列参照と、
""False と同等の扱いを受けることを利用して文字列を返す式がミソです。
小技として、==は2文字も使ってもったいないので<を使ってます。

6
2
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
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?