[Python] I want to add a string to another string with {} around that string

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    From the title it sounds very confusing but this is what I'm trying to say. We have a word, and I want to add it to mystring = "" but I want to have {} around the word (mind you I cant hard code it, I just have to use that variable)

    Normally to add a string to another string, I would do:

    mystring += word


    But I want to add {} around the word

    I've tried doing:

    mystring += {word}


    ^ {word} is not a string (different types)

    mystring += "{word}"


    ^ this just outputs {word} when you print it and not what the output string of word is

    mystring += f"{{word}}"


    ^ this outputs the same thing as above

    Any ideas?

    Continue reading...

Compartilhe esta Página