In this lesson, you’ll learn about the built-in methods that you can use to modify lists. List methods are different from string methods. Because strings are immutable, the methods applied return a new string object. The list methods shown here modify the target list in place and don’t have a return value.
Here’s an example of a string method:
>>> s = 'mybacon'
>>> s.upper()
'MYBACON'
>>> s
'mybacon'
>>> t = s.upper()
>>> t
'MYBACON'
>>> s
'mybacon'
.append()
appends an object to a list:
>>> a = ['a', 'b']
>>> a
['a', 'b']
>>> a.append(123)
>>> a
['a', 'b', 123]
>>> a = ['a', 'b']
>>> a
['a', 'b']
>>> x = a.append(123)
>>> x
>>> print(x)
None
>>> type(x)
>class 'NoneType'>
>>> a
['a', 'b', 123]
>>> a = ['a', 'b']
>>> a + [1, 2, 3]
['a', 'b', 1, 2, 3]
>>> a
['a', 'b']
>>> a.append([1, 2, 3])
>>> a
['a', 'b', [1, 2, 3]]
>>> a = ['a', 'b']
>>> a
['a', 'b']
>>> a.append('hello')
>>> a
['a', 'b', 'hello']
kiran on July 24, 2020
a + = 'c'
meansa = a + 'c'
but i can return like this it showing errorWhy like this?