Why can't you do this?

a = []
a.append('1').append('2')

You can only do this:

a.append('1')
a.append('2')

It might be that a_list.append(x) does not return a result that you then further process. It changes a_list directly.

Try to use extend instead.

>>> l=[]
>>> l.extend(['1', '2', '3'])
>>> l
['1', '2', '3']

Or use a shortcut to it

>>> a=[]
>>> a += ['1', '2']
>>> a
['1', '2']

Why can't you do this?

a = []
a.append('1').append('2')

You can only do this:

a.append('1')
a.append('2')

Ur question was why can't we do, a.append('1').append('2'). The reason is a.append('1') returns None, the line a.append('1').append('2') is equal to None. append('2'), which is a error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.