Why does
1.__add__(1)
yield SyntaxError: invalid syntax? What do the extra brackets add?
(1).__add__(1)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is an effect of the tokenizer:
1.__add__(1)is split into the tokens"1.","__add__","(","1", and")", since the tokenizer always tries to built the longest possible token. The first token is a floating point number, directly followed by an identifier, which is meaningless to the parser, so it throws aSyntaxError.Simply adding a space before the dot will make this work: