3.10 Lists - Syntax Terrors

Creating Lists

Key Points

  • Define lists with []

  • Store multiple values

  • Mix data types

JavaScript


let colors = ["red", "green", "blue"];
console.log(colors);


          

In JavaScript, you create a list (array) using [].

  • let colors = ["red", "green", "blue"]; creates an array called colors with three items.
  • Arrays can hold numbers, strings, or other arrays.
  • console.log(colors); prints the array to the console.

Arrays are a flexible way to store groups of values in JavaScript.

Python


colors = ["red", "green", "blue"]
print(colors)


          

In Python, you create a list using [].

  • colors = ["red", "green", "blue"] creates a list called colors with three items.
  • Lists can hold numbers, strings, or other lists.
  • print(colors) displays the list.

Lists are a basic way to store and organize data in Python.