Lists in Python (Part-I)

Adhithia
2 min readJun 13, 2021

What’s a Python list?

“A Python list is an ordered and mutable collection of data objects.”

Okay. But seriously, what is it?

Image by thehubbydiaries

Simply put, a list in Python is a type of data structure that can hold sequential data. And this data and its sequence can be edited or changed. The word mutable used in the first line is just a fancy way of saying that the data in a Python list can be edited after it has been created.

But what use is a list if you cannot store whatever data you want to. So Python list allows you to store multiple datatypes as well.

Creating Lists in Python

Creating a list in python is fairly easy. The syntax includes two square brackets on either sides of the data points (separated by comma) you want in the list.

Remember that the data points that are strings should be placed inside quotes.

"This is a string.", "I have placed them inside quotes."

Numbers (inclusive of integers, float etc) should be placed without quotes.

64, 43.25, 128, 1, 0, 100.013

We had mentioned that the Python lists can store multiple datatypes. And we saw examples of lists containing integers, float and string. Are these the only datatypes that are available in Python? Are lists confined to only these data types? Definitely not.

Python lists can hold other lists as an element (List of lists). Or even dictionaries for that matter (List of dictionaries).

Creating list of lists

I’m uploading these topics in no particular order. But that’s the end of Lists (Part I). Follow for more operations on lists in Part II.

--

--

Adhithia

MBA student at IIT Kharagpur — VGSOM ’23 | Former Data Scientist at Ashok Leyland | Machine Learning and Artificial Intelligence Enthusiast