-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
  • 107,083
  • 22
  • 201
  • 376

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.
  • 9,578
  • 2
  • 7
  • 12