• Home
  • Python
  • About
  • Lists

    Lists are collections of items.

    colors = ["red", "blue", "green", "pink"]
    
    # Items are accessed by index (starting from 0)
    print(colors[0]) # 'red'
    print(colors[1]) # 'blue'
    
    # Items can be modified
    colors[0] = "black"
    
    print(colors)
    # ['black', 'blue', 'green', 'pink']
    
    # Use `len` to find the length
    print(len(colors)) # 4
    
    # Use append to add new items to the end
    colors.append("brown")
    print(colors)
    # ['black', 'blue', 'green', 'pink', 'brown']
    Conditionals
    Loops
    Github Back to the top