-2

Consider a to be an array

print(a.append(1))

Why doesn't this print a's elements, it gives a message as None, whereas

print(a.index()) 

gives the desired result?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

1

Why doesn't this print a's elements

Why should it? append is meant to modify the list in-place. When you print(a.append(1)), you are appending 1 to a, and printing the result of calling append (the object returned by the append method), which is None.

Paul M.
  • 10,481
  • 2
  • 9
  • 15