-1
test = "123213 32543543 52354 234 34"
a = test.split().append("sd")
print (a)

The above code will give me a None in output, while the following code will output a list:

test = "123213 32543543 52354 234 34"
a = test.split()
a.append("sd")
print (a)

Can anyone explain it? Thanks.

PunyTitan
  • 277
  • 1
  • 9

2 Answers2

2

This is because .append() list operation returns None.

In [1]: list1 = [1,2,3,4] # some list

In [2]: a = list1.append(5) # append '5' to the list and assign return value to 'a'

In [3]: print a
None # means '.append()' operation returned None

In [4]: list1 
Out[4]: [1, 2, 3, 4, 5]

In [5]: list1.append(6) 

In [6]: list1
Out[6]: [1, 2, 3, 4, 5, 6]
Rahul Gupta
  • 46,769
  • 10
  • 112
  • 126
1

some_list.append() doesn't return the list some_list, it returns None, that's why

bakkal
  • 54,350
  • 12
  • 131
  • 107