• Home
  • Python
    • Introduction to Python
    • Python Developer
    • Expert Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
    • Expert JavaScript Developer
  • React.js
    • Introduction to React
    • React Developer
    • Expert React Developer
  • Linux
    • CyberSecurity - Introduction to Linux
    • CyberSecurity - Linux Administrator
    • CyberSecurity - Expert Linux Administrator
  • Active Directory
    • CyberSecurity - Introduction to Active Directory
    • CyberSecurity - Active Directory Administrator
    • CyberSecurity - Expert Active Directory Administrator
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • Python
      • Introduction to Python
      • Python Developer
      • Expert Python Developer
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
      • Expert JavaScript Developer
    • React
      • Introduction to React
      • React Developer
      • Expert React Developer
    • Linux
      • CyberSecurity - Introduction to Linux
      • CyberSecurity - Linux Administrator
      • CyberSecurity - Expert Linux Administrator
    • Active Directory
      • CyberSecurity - Introduction to Active Directory
      • CyberSecurity - Active Directory Administrator
      • CyberSecurity - Expert Active Directory Administrator
  • Interactive Training
  • Pricing
  • Brainstorm

Quick Links

  • About Us
  • Pricing
  • Brainstorm

Courses

  • Python
    • Introduction to Python
    • Python Developer
    • Expert Python Developer
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
    • Expert JavaScript Developer
  • React
    • Introduction to React
    • React Developer
    • Expert React Developer
    • Professional Master React Developer
  • Linux
    • CyberSecurity - Introduction to Linux
    • CyberSecurity - Linux Administrator
    • CyberSecurity - Expert Linux Administrator
  • Active Directory
    • CyberSecurity - Introduction to Active Directory
    • CyberSecurity - Active Directory Administrator
    • CyberSecurity - Expert Active Directory Administrator

Newsletter

Subscribe to our monthly newsletter, for a quick update on Python, JavaScript, React news

© 2024 - 2026 STEMTrainingGrounds. All Rights Reserved.

Lesson 5

Lesson 5 of 16

Lists

Lesson Progress: 0%

Code Example

# List of integers
nums1 = [1, 2, 3]
print(nums1)

nums2 = [5, 10, 15]
print(nums2)


# List of decimals
prices = [1.5, 2.0, 3.25]
print(prices)

heights = [4.2, 5.1, 6.0]
print(heights)


# List of words
pets = ["Cat", "Dog", "Bird"]
print(pets)

colors = ["Red", "Blue", "Green"]
print(colors)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • A list is like a backpack where you can store a whole collection of items together.
  • To make a list, we put all our items inside square brackets [ ].
  • We use commas to separate the items so Python knows where one ends and the next begins.
  • Your list can hold anything! It can be a group of numbers, decimals, or words.
  • When you give your list a name, like pets or colors, you can use it later in your code.
  • Just use print() with the list's name to see everything you stored inside it on the screen.

Code Example

# Case 1: List of short sentences (Example A)
quotes = ["Be kind", "Work hard", "Stay happy"]
print(quotes)

# Case 1: List of short sentences (Example B)
facts = ["The sky is blue", "Grass is green"]
print(facts)

# Case 2: List Indexing - Picking the first sentence
my_pets = ["I have a cat", "I have a dog", "I have a bird"]
print(my_pets[0])

# Case 2: List Indexing - Picking the last sentence
my_goals = ["Learn to code", "Play soccer", "Read a book"]
print(my_goals[2])

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • When you have a list of sentences, Python gives each one a "hidden number" to help you find it.
  • The first sentence in your list is always number 0, the second is number 1, and the third is number 2.
  • To grab just one sentence, put its number inside square brackets [ ] right after the list name.

Code Example

# List of different data types
mix1 = [5, "Hello", 2.5]
print(mix1)

mix2 = ["Cat", 10, True]
print(mix2)


# List indexing (getting one item from the list)
items1 = [7, "Apple", 3.5]
print(items1[0])

items2 = ["Dog", 4, False]
print(items2[1])

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • A list can hold different kinds of things, like numbers and words.
  • We use square brackets [ ] to get one item from a list.
  • Counting starts at 0, so [0] means the first item.
  • print() shows the list or the item on the screen.

Code Example

# Zip names with ages
names = ["Sam", "Alex"]
ages = [10, 12]

for name, age in zip(names, ages):
    print(name, age)


# Zip colors with objects
colors = ["Red", "Blue"]
things = ["Car", "Ball"]

for color, thing in zip(colors, things):
    print(color, thing)

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Python Code Editor

Task Incomplete

Editor Input:

Loading...

Editor Output:

Click "Run Code" to see the output here
  • The zip() helper is like a zipper on a jacket that pulls two different lists together into pairs.
  • It takes the first item from the first list and matches it perfectly with the first item from the second list.
  • In your loop, you use two names like name, age to hold the two pieces of information at the same time.
  • This is the best way to keep related data together, like matching a person's name with their favorite color or their age.
Lesson Progress: 0%
Lists
Lesson Incomplete
← Previous: Variables
Lesson 5 of 16
Next: String Operations →