Home Coding Data Structure – Lists

Data Structure – Lists

0
Data Structure – Lists

# Data Structure - List
# Want to have a single variable to carry on multiples values?
# One of Python's "most used" data structures is Lists.
# Lists are ordered and mutable, and yes, you can have
# the same values one or more times inside a list.
# Lists are also indexed so that the first item will be at index 0,
# the second item at index 1, etc. 
# Index in Python (and any other programming language)
# are odd, but we will talk about it later

# I'm an empty list. To declare a list,
# just put your data inside square brackets []
list1 = []            	

# I'm a list too, and I contain 4 items
list2 = [1,2,3,4]

# what the first item on list2 is? Yes is 1
out1 = list2[0]

# bacause items in list2 are numbers, you can add it
out2 = list2[1] + list2[2]

# what is that … len is a function that you can use on a list,
# and it stands for length
out3 = len(list2) 

# copy www.AEC.codes

OUT = (list1, list2, out1, out2, out3)