Creating Lists

In programming, we often have lots of data to handle. Instead of creating a new variable for every single item, we use a List. Think of a list as a storage shelf where you can keep everything from your favorite snacks to your exam scores!

What Makes a List Special?

A List is a collection that is ordered, changeable, and allows duplicates.

  • Square Brackets: We always create lists using [ ].

  • Commas: We separate each item with a ,.

  • Mix & Match: You can put numbers, words (strings), and even True/False (booleans) all in the same list!

Real-World List Examples

  • Class Roster: Storing every student's name in your grade.

  • Grocery Bag: ["apple", "banana", "mango"]

  • Scoreboard: Saving the points you earned in each level of a game.

How it Looks (Syntax & Examples)

The Pattern:

list_name = [item1, item2, item3]


Example 1: A List of Strings

fruits = ["apple", "banana", "mango"]
print(fruits)


Output: ['apple', 'banana', 'mango']

Example 2: A List of Numbers

numbers = [1, 2, 3, 4, 5]
print(numbers)


Output: [1, 2, 3, 4, 5]

Summary:

  • Duplicates Allowed: You can have [1, 1, 1] in a list, and Python won't mind!

  • Mutable: You can "mutate" or change the items whenever you need.

  • Versatile: Lists can be totally empty [] when you start and you can add items later.

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

Which of the following is a correctly written Python list?

Python uses square brackets [ ] to define a list.

Question 2

What do we use to separate items inside a list?

Every item in a list must be separated by a comma so Python knows where one item ends and the next begins.

Question 3

Can a single Python list store both a word (string) and a number?

Lists are very flexible and can hold a mix of strings, integers, and other types together.

Question 4

What does the term "Mutable" mean in Python?

Mutable means you can add, remove, or change items after the list has been created.

Question 5

What will be the output of print(len(["A", "B", "C"]))?

The len() function counts the number of items; since there are 3 items, the output is 3.

Congratulations!

You've successfully mastered the knowledge check for "Creating Lists."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic Lists