showing results for - "syntaxerror 3a f string expression part cannot include a backslash"
Jeffry
23 Apr 2020
1This is specified in the PEP for f-strings:
2Backslashes may not appear inside the expression portions of f-strings, [...]
3
4One option is assinging '\n' to a name and then .join on that inside the f-string; that is, without using a literal:
5Example:
6names = ['Adam', 'Bob', 'Cyril']
7nl = '\n'
8text = f"Winners are:{nl}{nl.join(names)}"
9print(text)
10
queries leading to this page
f string part cannot include backslashf string expression part cannot include a backslash 28 3cunknown 3e 2c line 119 29f string expression part cannot include a backslash 5cnf string cantaining new line in itpythonhow to print new line in python using fstringwhy f string cannot include backslashnew line in f literals pythonslash in f string pythonf string expression part cannot include a backslash 27 2cast error message 3a f string expression part cannot include a backslashnewlines with f stringf string python new linepython backslash in f stringpython line break f stringpython f string new line syntaxerror 3a f string expression part cannot include a backslashf string new linef string expression part cannot include a backslashf string cannot contain backslashinsert line break in python f string literalpython 5cn in f 22 printnew line in f string pythonnew line in python f stringf string cannot include a backslashpython 5cn not working in f stringf string expression part cannot include a backslasf string cannot include backslashf string cannot include backslashdon 27t show new line f string pythonline break in f string pythonpython defining f string in functionyntaxerror 3a f string expression part cannot include a backslashinitialize f string pythonsyntaxerror 3a f string expression part cannot include a backslashpython f string expression part cannot include a backslashf string expression cannot include a backslashf string expression part cannot include a backslash pythonsyntaxerror 3a f string expression part cannot include a backslash