Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.2K
Visualizações
How to fix Unterminated expression in f-string; missing close brace in python?

I want to use f string formatting instead of print. However, I get these errors: Unterminated expression in f-string; missing close brace Expected ')'

var="ab-c"
f"{var.replace("-","")}text123"

I tried to use single quote f'' and also double brackets but neither of them worked. Any idea about how to fix this?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Use single quotes:

var="ab-c"
f'{var.replace("-","")}text123'

# display abctext123
over 4 years ago · Santiago Trujillo Relatório

0

var = "ab-c"
f"{var.replace('-','')}text123"

always use a different quote character than the ones inside the f-string

over 4 years ago · Santiago Trujillo Relatório

0

For f"{var.replace("-","")}text123", Python parses f"{var.replace(" as a complete string, which you can see has an opening { and opening (, but then the string is terminated. It first expected a ) and eventually a }, hence the error you see.

To fix it, Python allows ' or " to enclose a string, so use one for the f-string and the other for inside the string:

f"{var.replace('-','')}text123"

or:

f'{var.replace("-","")}text123'

Triple quotes can also be used if internally you have both ' and "

f'''{var.replace("-",'')}text123'''

or:

f"""{var.replace("-",'')}text123"""
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda