Get Started

Extend a list

If you can change elements in a list, you sure want to be able to add elements to it, right? You can use the + operator:

x = ["a", "b", "c", "d"]
y = x + ["e", "f"]

You just won the lottery, awesome! You decide to build a poolhouse and a garage. Can you add the information to the areas list?

This is a part of the course

“Introduction to Python”

View Course

Exercise instructions

  • Use the + operator to paste the list ["poolhouse", 24.5] to the end of the areas list. Store the resulting list as areas_1.
  • Further extend areas_1 by adding data on your garage. Add the string "garage" and float 15.45. Name the resulting list areas_2.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create the areas list and make some changes
areas = ["hallway", 11.25, "kitchen", 18.0, "chill zone", 20.0,
         "bedroom", 10.75, "bathroom", 10.50]

# Add poolhouse data to areas, new list is areas_1
areas_1 = ____

# Add garage data to areas_1, new list is areas_2
areas_2 = ____

This exercise is part of the course

Introduction to Python

BeginnerSkill Level
4.8+
2319 reviews

Master the basics of data analysis with Python in just four hours. This online course will introduce the Python interface and explore popular packages.

Chapter 1: Python Basics

An introduction to the basic concepts of Python. Learn how to use Python interactively and by using a script. Create your first variables and acquaint yourself with Python's basic data types.

Exercise 1: Hello Python!Exercise 2: Your first Python codeExercise 3: Any comments?Exercise 4: Python as a calculatorExercise 5: Variables and TypesExercise 6: Variable AssignmentExercise 7: Calculations with variablesExercise 8: Other variable typesExercise 9: Operations with other types

Chapter 2: Python Lists

Learn to store, access, and manipulate data in lists: the first step toward efficiently working with huge amounts of data.

Exercise 1: Python ListsExercise 2: Create a listExercise 3: Create lists with different typesExercise 4: List of listsExercise 5: Subsetting ListsExercise 6: Subset and conquerExercise 7: Slicing and dicingExercise 8: Subsetting lists of listsExercise 9: Manipulating ListsExercise 10: Replace list elementsExercise 11: Extend a list
Exercise 12: Delete list elementsExercise 13: Inner workings of lists

Chapter 3: Functions and Packages

You'll learn how to use functions, methods, and packages to efficiently leverage the code that brilliant Python developers have written. The goal is to reduce the amount of code you need to solve challenging problems!

Exercise 1: FunctionsExercise 2: Familiar functionsExercise 3: Help!Exercise 4: Multiple argumentsExercise 5: MethodsExercise 6: String MethodsExercise 7: List MethodsExercise 8: List Methods (2)Exercise 9: PackagesExercise 10: Import packageExercise 11: Selective importExercise 12: Different ways of importing

Chapter 4: NumPy

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free