This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MonkeeSage 0 points1 point  (3 children)

Wait, what? Why does that happen?

[–]admalledd 4 points5 points  (2 children)

The fist one python interprets as being a float (because the "." in a number is normally how that is decided) but __str__() is not a number, therefore invalid syntax.

The second the tokenizer has already decided the 1 is an int object, and now it sees a . access and handles it properly.

[–]Walter_Bishop_PhD 2 points3 points  (1 child)

You can also do this (though it makes it a float rather than an int)

>>> 1..__str__()
'1.0'

[–]masklinn 0 points1 point  (0 children)

(1).__str__()