FizzBuzz with Python3

Background

Four days after I started writing Python for business, I realized that I had never written FizzBuzz in Python, although I was able to implement business logic, so I tried it. Only try FizzBuzz, which is less readable, to get a feel for the detailed language specifications.

FizzBuzz In order to make it one-liner and as difficult to read as possible, I tried a ternary operator-like thing in the era when ternary operators and ternary operators did not exist.

[print(x) for x in [('Buzz' if i % 5 == 0 else 'Fizz' if i % 3 == 0 else i, 'FizzBuzz')[i % 15 == 0] for i in range(1, 101)]]

it is a good feeling!

By the way, it doesn't work in Python2 system because print is not a function. I wanted to write it so that it would work with Python 2 system, but I gave up because of lack of ability ...

Why don't you write the code whose readability is dead under the cause of understanding the language specifications?

that's all.

Recommended Posts

FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
FizzBuzz in Python
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Non-blocking with Python + uWSGI
Scraping with Python + PhantomJS
Posting tweets with python
Drive WebDriver with python
Use mecab with Python3
[Python] Redirect with CGIHTTPServer
Voice analysis with python
Think yaml with python
Operate Kinesis with Python
Getting Started with Python
Use DynamoDB with Python
Zundko getter with python
Handle Excel with python
Ohm's Law with Python
Primality test with python
Run Blender with python
Solve Sudoku with Python
Python starting with Windows 7
Heatmap with Python + matplotlib
Multi-process asynchronously with python
Python programming with Atom