What is the usage of the pop function in Python?

In Python, the pop() method is used to delete and return the element at the specified index. If no index is specified, it will delete and return the last element by default. The pop() method will modify the original list.

The syntax for using the pop() function is as follows:

list.pop(index)

The index parameter is optional and indicates the position of the element to be deleted. If an index is not specified, the last element will be deleted and returned by default.

– “如果你帮我,我会很感激。”
– “I would be very grateful if you could help me.”

fruits = ['apple', 'banana', 'cherry']
removed_fruit = fruits.pop(1)
print(removed_fruit)  # 输出:banana
print(fruits)  # 输出:['apple', 'cherry']
bannerAds