Skip to content

Instantly share code, notes, and snippets.

@tcpdump-examples
Created March 5, 2022 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcpdump-examples/02ec554a60f79082a245b99d0bb73342 to your computer and use it in GitHub Desktop.
Save tcpdump-examples/02ec554a60f79082a245b99d0bb73342 to your computer and use it in GitHub Desktop.

Example 1

#a list

cars = ['Ford', 'Volvo', 'BMW', 'Tesla']

#append item to list

cars.append('Audi')

print(cars)

Example 2

list = ['Hello', 1, '@']

list.append(2)

list

['Hello', 1, '@', 2]

Example 3

list = ['Hello', 1, '@', 2]

list.append((3, 4))

list

['Hello', 1, '@', 2, (3, 4)]

Example 4

list.append([3, 4])

list

['Hello', 1, '@', 2, (3, 4), [3, 4]]

Example 5

list.append(3, 4)

Traceback (most recent call last):

File "", line 1, in

TypeError: append() takes exactly one argument (2 given)

Example 6

list.extend([5, 6])

list

['Hello', 1, '@', 2, (3, 4), [3, 4], 5, 6]

list.extend((5, 6))

list

['Hello', 1, '@', 2, (3, 4), [3, 4], 5, 6, 5, 6]

list.extend(5, 6)

Traceback (most recent call last):

File "", line 1, in

TypeError: extend() takes exactly one argument (2 given)

Reference:

how to append list in python

how to add items to a list in python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment