Python .pop
Python gives us a method to remove elements at a specific index using a method called .pop().
# Example: Travel Destinations
travel_destinations = ["Paris", "Tokyo", "New York", "Sydney", "Cairo", "Rome"]
print(travel_destinations)
# Checkpoint 2: Remove the last destination
travel_destinations.pop()
print(travel_destinations)
# Checkpoint 3: Remove the 2nd destination (index 1)
travel_destinations.pop(1)
print(travel_destinations)
Comments
Post a Comment