Revision 130b705e-fd66-4ae1-a36b-a10b00742a7a - Code Golf Stack Exchange

## Python 3: 15, 17, or 18 characters

[mdeitrick's answer](https://codegolf.stackexchange.com/questions/13152/shortest-code-to-produce-infinite-output/15188#15188) is longer in Python 3, which replaces the `print` statement with a function call (15 chars):

 while 1:print()

This remains the shortest I've found in Python 3. However, there are some more-interesting ways of printing in an infinite loop that are only a few characters longer.

* `print()` returns `None`, which != 9, making it an infinite loop; the `8` is a no-op that substitutes for `pass` (18 chars):

 while print()!=9:8

* `iter(print, 9)` defines an iterable that returns the output of `print()` until it equals `9` (which never happens). `any` consumes the input iterable looking for a true value, which never arrives since `print()` always returns `None`. (You could also use `set` to the same effect.)

 any(iter(print,9))

* Or, we can consumer the iterable by testing whether it contains `8` (17 chars):

 8in iter(print,9)

* Or, [unpack it using the splat operator](https://codegolf.stackexchange.com/questions/54/tips-for-golfing-in-python/4389#4389):

 *_,=iter(print,9)

* The weirdest way I thought of is to use splat destructuring inside a function call, `function(*iterable)`. It seems that Python tries to consume the entire iterable before even attempting the function call—even if the function call is bogus. This means that we don't even need a real function, because the type error will only be thrown after the iterable is exhausted (i.e. never):

 8(*iter(print,9))

AltStyle によって変換されたページ (->オリジナル) /