Accessing attributes on literals work on all types, but not `int`; why? [duplicate]

You need parens:

(4).__str__()

The problem is the lexer thinks “4.” is going to be a floating-point number.

Also, this works:

x = 4
x.__str__()

Leave a Comment