list

Cards (12)

  • What is the purpose of lists in programming?
    To store multiple items in a single variable
  • How is a list declared in a similar fashion to variables?
    By using square brackets to define items
  • What does accessing data in lists involve?
    Using square brackets with an index
  • What is the starting index for items in a list?
    0
  • What is the purpose of the append method in lists?
    To add an item to the end of the list
  • How would you add "yellow" to a list of colors?
    colors.append("yellow")
  • What does the remove method do in lists?
    It deletes a specified item from the list
  • How would you remove "blue" from a list of colors?
    colors.remove("blue")
  • What does the pop method do in lists?
    It removes and returns an item at a specified index
  • How would you use pop to remove the first color?
    colors.pop(0)
  • What is the output of colors.pop(0) if colors = ["red", "blue", "green"]?
    "red"
  • What are the key operations you can perform on lists?
    • Accessing items by index
    • Adding items with append
    • Removing items with remove and pop
    • Iterating through items in a loop