In this chapter, we will create simple python programs that will demonstrate the usage of various python list methods.

# create a simple python program which will manipulate the content of a python list data type

student_group = []
student_group.append("Rock") # add a student to the group
student_group2 = ["Rick", "Robert", "Robetto"]
student_group.extend(student_group2) # add the list of the second group to the first
student_group.insert(1, "Ray") # insert Rick at index 1 in the list
student_group.remove("Robetto") # remove Robetto from the student list
student_group.sort() # sort the list according to alphabet order
student_group2.reverse() # reverse the order of the student_group2 list
The outcome of the above python list methods program

In the below python list program we will loop through the above python list just like any iterable object.

for name in student_group:
    print(name) # print out the name for each student within the first student group
The names within the first student group

In the next chapter, we will write a short python program which will further explore the usage of the python list!

Please follow and like us:

Leave a Reply

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