0

I find that this works :

a = list(('i', 'am'))
a.append('a')
a

['i', 'am', 'a']

but not this :

b = list(('i','am')).append('a')
b
azpiuser
  • 311
  • 1
  • 9

1 Answers1

3

b isn't assigned the list; it is assigned the result of the append method, which is None.

Put another way, b = list(('i','am')).append('a') is not interpreted as

(b = list(('i','am'))).append('a')

Starting in Python 3.8, you could write

(b := list(('i', 'am'))).append('a')

using the assignment expression operator := to get the desired effect, but I feel confident in claiming that would be considered poor style.

chepner
  • 497,756
  • 71
  • 530
  • 681