A
A
aab1372021-08-21 11:54:40
Python
aab137, 2021-08-21 11:54:40

How to write "\n" in python f-string?

I want to do this.
f"фыва{'\n'.join(lst)}пролджэ"
But it doesn't work out that way because of the slash.
You can, of course, add lines. But how to do it in style?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2021-08-21
@aab137

one.

nl = "\n"
f"фыва{nl.join(lst)}пролджэ"

2.
f"фыва{chr(10).join(my_list)}пролджэ"

Z
ZIK1337, 2021-08-21
@ZIK1337

there is no way to write https://www.python.org/dev/peps/pep-0498/#escape-s... in the f-line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question