Skip to content Skip to sidebar Skip to footer

Why Do I Need To Enclose A Literal In Parentheses While Invoking A Method?

Without () 42.__abs__() File '', line 1 42.__abs__() ^ SyntaxError: invalid syntax With () (42).__abs__() 42 What is the r

Solution 1:

42. will be interpreted by the parser as a float 42.0. Ergo the . is not recognized as the connector between an instance and one of its methods. Python rightfully complains that there is some variable name directly after a float, since that is invalid syntax.


Post a Comment for "Why Do I Need To Enclose A Literal In Parentheses While Invoking A Method?"