How to Add New Line in Python f-strings

How to Fix SyntaxError: f-string expression part cannot include a backslash

Giorgos Myrianthous
Towards Data Science
3 min readJun 15, 2021

--

Photo by Kevin Mak on Unsplash

Introduction

In Python, it’s impossible to include backslashes in curly braces {} of f-strings. Doing so will result into a SyntaxError:

>>> f'{\}'
SyntaxError: f-string expression part cannot include a backslash

--

--

I strive to build data-intensive systems that are not only functional, but also scalable, cost effective and maintainable over the long term.