In Python 2.x, using backticks to get decimal string from int object is Horrible? -


In Python 2.x, backtakes are used to get decimal string from int object horrible ? Because backtax is repr () , is not str () ? I have seen that when I answer the question.

In Python source, they are the same function in the Python source,

  (reprfunc) int_to_decimal_string, / * tp_repr * / .. .. (reprfunc) int_to_decimal_string, / * Tp_str * /  

What do you think?

Well, I would not say that this is "terrible", but I think at least four For reasons this is not true:

  1. str (My_number) by backtax my_number Describes intentions (see "readability count").

  2. Python implementation in C is just a possible implementation; There is no clear statement in the Python specification that there are Jethon, IronPathon, PAP and so on, and that repr () and str () are equal for integer Objects, I would not trust that behavior.

  3. The backtraces are run in Python 3.x.

  4. If your number is so large that it can not be displayed by int , Python promotes itself to a longer integer , And for that, repr () and Str () are different.

See this example:

  & gt; & Gt; & Gt; X = 1234567890> & gt; & Gt; & Gt; Y = x ** 3> gt; & Gt; `Y` '1881676371789154860897069000L' & gt; & Gt; & Gt; Str (y) '1881676371789154860897069000' ' 

Comments