1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Why doesn’t this f-string with double quotes raise a SyntaxError in Python 3.13.3?...

Discussão em 'Python' iniciado por Stack, Setembro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I'm currently following this Python course course from Harvard.

    At the point in the video, the instructor shows that the following code should raise a SyntaxError because of the conflicting double quotes inside the f-string:

    def main():
    student = get_student()
    print (f"{student["name"]} from {student["house"]}")

    def get_student():
    # First I create an empty dict
    student = {}
    # Then I set the keys
    student["name"] = input ("Name: ")
    student["house"] = input ("House: ")

    return student

    if __name__ == "__main__":
    main()


    According to the instructor (and what I’ve also found online), this line:

    print (f"{student["name"]} from {student["house"]}")


    shouldn’t work, since the double quotes around name and house conflict with the surrounding double quotes of the f-string.

    However, I’m running this in Python 3.13.3, and surprisingly it runs fine. For example, entering Harry and Gryffindor prints: Harry from Gryffindor

    No error at all.

    Why is this working for me without raising a SyntaxError? Has something changed in Python 3.13 regarding f-strings, or am I misunderstanding something in my setup?

    Continue reading...

Compartilhe esta Página