DEV Community

Discussion on: Introduction To Python Lists

Collapse
 
xoeseko profile image
Xoeseko

Nice intro! I think you had a couple typos though

list.extend 
#output: c++ and c are missing
Enter fullscreen mode Exit fullscreen mode

Then,

list.pop()
Enter fullscreen mode Exit fullscreen mode

You have an index in the first one too.

I was also surprised you didn't give the output for the last methods you showed.

Nice writing otherwise keep it up

Collapse
 
cindyachieng profile image
Cindy Achieng

Thank you for that observation,I will edit the post soon enough

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