A=s.append(s[i]+A+B)
A=s.append(s[i]+A+B)
TypeError: unsupported operand type(s) for +: ‘long’ and ‘str’
What does this error mean ? A and B are strings and s is a list
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.
smay be a list, but the element –s[i]– is not – it’s a long, as indicated by the error.In addition,
append()operates on the list directly – it returnsNone, so you’re actually settingAto be None – probably not what you wanted!There are two things you can do to help avoid this type of error in the future.
Don’t use one-letter variable names. Use descriptive, one to three-word length names that describe what the variable has in it (and/or what it’s supposed to be used for).
When you do have a problem, try putting it in a try/except block where you put the error name after
exceptand print out the offending variables:Don’t forget the
raiseat the end there – that way you don’t just ignore the issue and start getting really strange errors.