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:
-
str (My_number)by backtaxmy_numberDescribes intentions (see "readability count"). -
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 ()andstr ()are equal for integer Objects, I would not trust that behavior. -
The backtraces are run in Python 3.x.
-
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 ()andStr ()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
Post a Comment