Skip to content

Instantly share code, notes, and snippets.

@iJKTen
Created June 10, 2020 18:18
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 iJKTen/2e47a31f7b2a616a245418484975fae4 to your computer and use it in GitHub Desktop.
Save iJKTen/2e47a31f7b2a616a245418484975fae4 to your computer and use it in GitHub Desktop.
arr = []
arr.append(1)
arr.append(2)
arr.insert(2, 3)
arr.insert(3, 4)
# Add elements with a for loop
for index in range(4):
arr.append(index + 5)
# Our list now has 8 elements [1, 2, 3, 4, 5, 6, 7, 8]
arr[0]
arr[1]
# Output the length of the list
len(arr)
# Get the last element in the list
arr[len(arr) - 1]
for item in arr:
print(item)
# using enumerator
for index, item in enumerate(arr):
print(arr[index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment