list of objects in python code example

Example 1: python list

# Create list
List = list()
List = []
List = [0, "any data type can be added to list", 25.12,
        ("Even tuples"), {"Dictionaries": "can also be added"},
       ["can", "be nested"]]
# Accessing items

List[1]		# 0
List[-1] 	# ["can", "be nested"]

# Operations
List.append(4)		# adds 4 to end
List.pop(n=-1)		# removes element from nth position
List.count(25.12)	# 1

Example 2: python list of objects

# Create a new class
class MyClass(object):
    def __init__(self, number):
        self.number = number


# Create a array to store your objects
my_objects = []

# Add 100 objects to array
for i in range(100):
    my_objects.append(MyClass(i))