DEV Community

Discussion on: Introduction To Python Lists

Collapse
 
cindyachieng profile image
Cindy Achieng

I understand the misunderstanding on extend() method and I have used a more clear example by defining a second list

languages = ['java', 'python' ,'perl', 'ruby', 'c#']

Languages2=['c++', 'c']

languages.extend(Languages2)

print(languages)
# Output ['java', 'python', 'perl', 'ruby', 'c#', 'c++', 'c']

You are right, when we simply use Pop() without specifying the item position,It removes the last item and returns the value which has been removed

languages = ['java', 'python' ,'perl', 'ruby', 'c#']

print(languages.pop()) # returns c#, the last index

print(languages) # print the  after removing c#

# output ['java', 'python', 'perl', 'ruby']

Thanks