[Python] Understanding repr( ) function in Python

Discussão em 'Python' iniciado por Stack, Agosto 7, 2025.

  1. Stack

    Stack Membro Participativo

    repr(): evaluatable string representation of an object (can eval() it, meaning it is a string representation that evaluates to a Python object)

    In other words:

    >>> x = 'foo'
    >>> repr(x)
    "'foo'"


    Questions:

    1. Why do I get the double quotes when I do repr(x)? (I don't get them when I do str(x))
    2. Why do I get 'foo' when I do eval("'foo'") and not x which is the object?

    Continue reading...

Compartilhe esta Página