How to use newline ‘\n’ in f-string to format output in Python 3.6?

I would like to know how to format this case in a Pythonic way with f-strings: names = [‘Adam’, ‘Bob’, ‘Cyril’] text = f”Winners are:\n{‘\n’.join(names)}” print(text) The problem is that ‘\’ cannot be used inside the {…} expression portions of an f-string. Expected output: Winners are: Adam Bob Cyril 6 Answers 6

String formatting: % vs. .format vs. f-string literal

Python 2.6 introduced the str.format() method with a slightly different syntax from the existing % operator. Which is better and for what situations? Python 3.6 has now introduced another string formatting format of string literals (aka “f” strings) via the syntax f”my string”. Is this formatting option better than the others? The following uses each … Read more