-6

I have this code right here that I was using and I was trying out the .append() function.

x=[1, 2, 3, 4]
x.append(5)
print(x)

But what does the .append() function actually do?

Daniel Walker
  • 5,220
  • 3
  • 18
  • 39
  • 4
    What did you see from the `print`? – Daniel Walker Jan 07 '21 at 02:20
  • Welcome to SO, please before asking a question perform a search first. This question can be simply answered without causing a duplicate question. Even consult the docs they may have the answer in there too. – Jab Jan 07 '21 at 02:24

1 Answers1

1

The append() method in Python adds a single item to the existing list. It doesn't return a new list of items but will modify the original list by adding the item to the end of the list. After executing the method append on the list the size of the list increases by one.

Daniel Walker
  • 5,220
  • 3
  • 18
  • 39
Marquez
  • 19
  • 1