Skip to content

Joseph-T-Gordon

A complete log of all recent projects and skills

Menu
  • About me
  • Posts/Projects
  • Resume/Certifications
Menu

Post #38 (Python Programming) – Lists in python

Posted on March 24, 2023June 26, 2023 by admin

Lists in python are quite powerful, it is essentially a variable that can hold multiple values

Code:

list = [1, 2, 3, 4 ,5]

print(list)

Result:

[1, 2, 3, 4, 5]

You can also call specific items in a list as well as append an item to the append end of the list, the lists start at 0 not 1, be sure to keep that in mind. list_name.append(New Value). You can also insert items and a specific index this will push all other items in the index up 1 in front of it list list_name(index, value)

Code:

list = []

list.append(1)

print(list[0])

list.append(0,5)

print(list)

Result:

1

[5, 1]

I’m sure you’re starting to get tired of all this list so let me finish off by saying you can use del list_name[index] to delete an item in your list there is also the len command which displays the number of items currently in your list. Last but not least you can use the for loop, mentioned in post #37 https://joseph-t-gordon.tech/index.php/2023/03/21/post-37-the-power-of-loops-in-python/ to go through all the items within a list.

Code:

list = [1, 2, 3, 4, 5]

del list[0]

list_total = 0

print(len(list))

print(list)

for i in list:

list_total += i

print(list_total)

Result:

4

[2, 3, 4, 5]

14

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2025 Joseph-T-Gordon | Powered by Minimalist Blog WordPress Theme