Tuples and List Notes
Tuples and List Notes
List Methods
Reverse a List
This program demonstrates how to reverse the elements of a list using the reverse() method.
This program shows how to remove and return the last element using pop().
Sort a List
This program demonstrates how to sort a list in ascending order using the sort() method.
This program demonstrates how to add an element to the end of the list using append().
This program shows how to insert an element at a specific index using insert().
Tuple Methods
Using count() method
The count() method returns the number of times a specified value appears in a tuple.
# Creating a tuple
my_tuple = (1, 2, 3, 4, 2, 2, 5)
The index() method returns the first index of the specified value in a tuple.
# Creating a tuple
my_tuple = ('apple', 'banana', 'cherry', 'banana', 'date')