Here’s fizzbuzz in one line of Python:

print('/n'.join([('Fizz' * (i % 3 == 0) 
                    + 'buzz' * (i % 5 == 0)) 
                or str(i) 
                for i in range(1,101)])) 

This illustrates several interesting features of Python:

  • When you apply * to a str and int, you will get the str repeated the number of times of the int
    • When you apply * to a str and bool, it will give you either 0 or 1 copies of the str, because bool is a subclass of int in Python
  • When you apply + to two strs, you get the strs concatenated together
  • You can or together strs and they will be interpreted based on Python truthiness rules. That is, an empty string is False and everything else is True.
    • Furthermore, the result of oring together any data types will not always be True or False, but one of the inputs of the or expression. x or y really means x if x else y.