How to create and use lists in Python

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

n Python, a list is a data structure used to store multiple values in a single variable. Lists are enclosed in square brackets [] and the values inside are separated by commas.

Here is an example of how to create a list in Python:

#creating a list of numbers
numbers = [1, 2, 3, 4, 5]

#creating a list of strings
fruits = ['apple', 'banana', 'orange']

#creating a list of mixed data types
mixed_list = [1, 'hello', 3.14, True]

You can also create a list using the list() constructor which takes an iterable object as an argument:

#creating a list from a range of numbers
numbers = list(range(1, 6))

#creating a list from a string
letters = list("hello")

You can add, remove, or modify elements in a list, and use various list methods such as append(), insert(), remove() and more.

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.