About 38,700 results
Open links in new tab
  1. Understanding repr( ) function in Python - Stack Overflow

    Understanding repr( ) function in Python. Ask Question Asked 13 years, 6 months ago.

  2. python - Purpose of __repr__ method? - Stack Overflow

    Feb 21, 2021 · The returns of repr() and str() are identical for int x, but there's a difference between the return values for str y-- one is formal and the other is informal. One of the most important differences between the formal and informal representations is that the default implementation of __repr__ for a str value can be called as an argument to eval ...

  3. What is the difference between __str__ and __repr__?

    On page 358 of the book Python scripting for computational science by Hans Petter Langtangen, it clearly states that . The __repr__ aims at a complete string representation of the object; The __str__ is to return a nice string for printing. So, I prefer to understand them as. repr = reproduce; str = string (representation)

  4. python - What does !r do in str() and repr()? - Stack Overflow

    Feb 7, 2012 · str and repr. str is generally a little more human friendly, repr is generally more precise. Perhaps the official documentation is the best place to go looking for the difference: object.__repr__(self) Called by the repr() built-in function to compute the “official” string representation of an object. If at all possible, this should look ...

  5. python - What is the purpose of __str__ and __repr__? - Stack …

    Called by the repr() built-in function and by string conversions (reverse quotes) to compute the "official" string representation of an object. If at all possible, this should look like a valid Python expression that could be used to recreate an object with the same value (given an appropriate environment). __str__

  6. string - str () vs repr () functions in python 2.7.5 - Stack Overflow

    Oct 12, 2013 · what is the difference between str() and repr() functions in python 2.7.5? Explanation on python.org: The str() function is meant to return representations of values which are fairly human-reada...

  7. python - Writing a repr method - Stack Overflow

    Jun 13, 2016 · The __repr__ function returns a string representation of a Python object that may be evaluated by the Python interpreter to instantiate another instance of the object. So if you had a list: x = ['foo', 'bar'] Its __repr__ string would be: x_str = repr(x) print(x_str) >>>> "['foo', 'bar']" And you could do:

  8. python - Best output type and encoding practices for __repr__ ...

    Dec 13, 2012 · Is there a best encoding for the result of __repr__() in Python? What I want to output does have non-ASCII characters. I use Python 2.x, and want to write code that can easily be adapted to Python 3. The program thus uses # -*- coding: utf-8 -*- from __future__ import unicode_literals, print_function # The 'Hello' literal represents a Unicode ...

  9. funções - Afinal para que serve a função repr no python? - Stack ...

    May 1, 2017 · O repr chama o método interno __repr__ do objeto. A ideia dele é retornar uma representação como string de qualquer objeto - mas pensando antes no programador do que no usuário final do programa. Sobretudo é o repr que é chamado para cada resultado de expressão quando usamos o Python no modo interativo.

  10. Python repr for classes - Stack Overflow

    Mar 12, 2013 · I can see in the answers that it is not clear in the discussion what repr should return. The way I see it, the repr function should return a string that allows you to reproduce the object: in an arbitrary context and ; automatically (i.e. not manually). Ad.1. Take a look at a built-in class case (taken from this SO question):

Refresh