Skip to content
Advertisement

append string to list/string returns ‘None’ or ‘AttributeError: ‘str’ object has no attribute ‘append” in python

I’m trying to add 1 word/string to the back of the sentence ‘Afterall , what affects one family ‘.

Using the append method, it either returns ‘None’ if I append directly to the list or it will return an error ‘AttributeError’ if I append to the string. May I know how do I add the word/string to the back of the sentence?

JavaScript

Advertisement

Answer

The difference here is that, in Python, a “list” is mutable and a “string” is not — it cannot be changed. The “list.append” operation modifies the list, but returns nothing. So, try:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement