Python_List_Tuple_Function_String_Methods (1)
Python_List_Tuple_Function_String_Methods (1)
Example:
my_list = [1, 2, 3]
Example:
my_list = [1, 2]
Example:
my_list = [1, 3]
Example:
my_list = [1, 2, 3]
5. pop(index) - Removes and returns an item at the specified index. Default is the last item.
Example:
my_list = [1, 2, 3]
Example:
my_list = [1, 2, 3]
my_list.index(2) # Returns 1
Example:
my_list = [1, 2, 2, 3]
my_list.count(2) # Returns 2
Example:
my_list = [1, 2, 3]
Example:
my_list = [3, 1, 2]
Example:
my_list = [1, 2, 3]
Example:
my_tuple = (1, 2, 3)
Tuple Methods:
Example:
my_tuple = (1, 2, 2, 3)
my_tuple.count(2) # Returns 2
Example:
my_tuple = (1, 2, 3)
my_tuple.index(2) # Returns 1
Python Functions and Methods
Example:
def greet(name):
Custom Functions:
Example:
return a + b
Function Methods:
Functions do not have specific methods like lists or tuples, but they can be treated as objects.
Python List Methods
Example:
my_list = [1, 2, 3]
Example:
my_list = [1, 2]
Example:
my_list = [1, 3]
Example:
my_list = [1, 2, 3]
5. pop(index) - Removes and returns an item at the specified index. Default is the last item.
Example: