How does Python evaluate the expression 1+++2?
How many ever + I put in between, it is printing 3 as the answer. Please can anyone explain this behavior
And for 1--2 it is printing 3 and for 1---2 it is printing -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.
Your expression is the same as:
Any numeric expression can be preceded by
-to make it negative, or+to do nothing (the option is present for symmetry). With negative signs:and
I see you clarified your question to say that you come from a C background. In Python, there are no increment operators like
++and--in C, which was probably the source of your confusion. To increment or decrement a variableiorjin Python use this style: