Skip to main content
\(\require{cancel}\)
Physics LibreTexts

28.2: Arrays

  • Page ID
    19589
  • It is often the case that we need to represent a series of numbers. For example, imagine that you have measured the position of an object as a function of time. Arrays are a convenient way to hold a series of numbers that are all alike, for example, all of the values of the position and corresponding time values for the trajectory of the object. In Python, we can define variables that hold arrays instead of a single value (arrays are called “lists” in Python):

    python code \(\PageIndex{1}\)

    Arrays in python

    #define an array of values for the position of the object
    position = [0 ,1 ,4 ,9 ,16 ,25]
    #define an array of values for the corresponding times
    time = [0 ,1 ,2 ,3 ,4 ,5]
    
    • Was this article helpful?