Python Introducing Lists Using Lists Continental

Farhan Murad
Farhan Murad
1,920 Points

List

I do not know how to print only Asia and South America from this list. It is supposed to look something like this: "* Asia

  • South America"
continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
continents.pop(0,1)

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 23,719 Points

You are close! Python pop() method works only on one element at at time.

documentation here:

https://www.programiz.com/python-programming/methods/list/pop

One way to do this is below. However, continents is altered and will no longer have the first two elements of the list after you run the code.

Since pop(0) removes the FIRST element of the list, you call it twice.

print(continents.pop(0))
print(continents.pop(0))

A non-deleting method to acheive the task is below:

print(continents[0])
print(continents[1])

Good luck with your Python journey, there are a lot of cool apps waiting for you to build!