Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

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 Answer

0 votes
by (106k points)

You can understand by seeing the below-mentioned code:-

foo = 'bar' 

baz(foo)

you are not passing foo to the baz function. foo is just a name used to represent a value, in this case, 'bar', and that value is passed to the baz function.

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
3 answers
asked Sep 20, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
asked Dec 17, 2020 in Python by laddulakshana (16.4k points)
+1 vote
2 answers

Browse Categories

...