Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6692985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:55:50+00:00 2026-05-26T05:55:50+00:00

repr() : evaluatable string representation of an object (can eval() it, meaning it is

  • 0

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?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:55:50+00:00Added an answer on May 26, 2026 at 5:55 am
    >>> x = 'foo'
    >>> x
    'foo'
    

    So the name x is attached to 'foo' string. When you call for example repr(x) the interpreter puts 'foo' instead of x and then calls repr('foo').

    >>> repr(x)
    "'foo'"
    >>> x.__repr__()
    "'foo'"
    

    repr actually calls a magic method __repr__ of x, which gives the string containing the representation of the value 'foo' assigned to x. So it returns 'foo' inside the string "" resulting in "'foo'". The idea of repr is to give a string which contains a series of symbols which we can type in the interpreter and get the same value which was sent as an argument to repr.

    >>> eval("'foo'")
    'foo'
    

    When we call eval("'foo'"), it’s the same as we type 'foo' in the interpreter. It’s as we directly type the contents of the outer string "" in the interpreter.

    >>> eval('foo')
    
    Traceback (most recent call last):
      File "<pyshell#5>", line 1, in <module>
        eval('foo')
      File "<string>", line 1, in <module>
    NameError: name 'foo' is not defined
    

    If we call eval('foo'), it’s the same as we type foo in the interpreter. But there is no foo variable available and an exception is raised.

    >>> str(x)
    'foo'
    >>> x.__str__()
    'foo'
    >>> 
    

    str is just the string representation of the object (remember, x variable refers to 'foo'), so this function returns string.

    >>> str(5)
    '5'
    

    String representation of integer 5 is '5'.

    >>> str('foo')
    'foo'
    

    And string representation of string 'foo' is the same string 'foo'.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that repr() 's purpose is to return a string, that can be
Are there any security exploits that could occur in this scenario: eval(repr(unsanitized_user_input), {__builtins__: None},
In Python 2.x, using backticks to get decimal string from int object is Horrible
I just learned yesterday from this site that I can: class Seq(object): def __init__(self,
The __repr__ function of python is fancy as it is called when print OBJECT
When you call the object.__repr__() method in Python you get something like this back:
An ordinary object, I can use o.__repr__() to see something like '<__main__.A object at
In this question , it was suggested that calling repr on a dictionary would
Given a string named line whose raw version has this value: \rRAWSTRING how can
Suppose I have the following object: class Foo(object): def __init__(self, name=None): self.name = name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.