List and Arrays

Cards (13)

  • What is the purpose of variables in programming?

    To store one data value at a time
  • Why would creating separate variables for each age be confusing?

    Because it would take up space and become unmanageable
  • What is a list in programming?

    A data structure that allows storing multiple data values under one name
  • How does an array differ from a regular list in Python?

    An array is a type of list that requires all values to be of the same data type
  • How do you create an array in Python?

    By surrounding all values with square brackets []
  • What is the syntax to create an array of names in Python?

    names = ['Ethan', 'Mary', 'Bob', 'Alice']
  • What is the syntax to create an array of ages in Python?

    ages = [16, 9, 22, 8]
  • What does the index number of an array start from?

    0
  • How would you access the third name in the names array?

    By using print(names[2])
  • How would you access the second age in the ages array?

    By using print(ages[1])
  • What method is used to add a new value to the end of a list in Python?

    The append method
  • How would you add "MC Chillerts" to the names array?

    By using names.append("MC Chillerts")
  • What are the key characteristics of lists and arrays in Python?

    • Lists store multiple data values under one name.
    • Arrays are a type of list with the same data type for all values.
    • Arrays are created using square brackets [].
    • Indexing starts from 0.
    • The append method adds values to the end of a list.