Understanding Lists in Python- Wakeupcoders

Lists in Python

In Python, multiple elements can be kept in a single variable by using lists. One of the four built-in data types in Python for storing data collections is the list. The other three are the tuple, set, and dictionary, each of which has a unique purpose. Let’s move to understand the lists in python

Python List

example:

fruits = ["strawberry", "mango", "date"]
print(fruits)

What exactly List is?

Example of list

List items can have duplicate values and are sorted and editable. The first item in a list has the index [0], the second item has the index [1], etc.

When we refer to a list as being sorted, we indicate that the entries are in a specific order that will not alter. The new things will be added at the end of the list if you add more items. The list is modifiable, which means that after it has been generated, we may edit, add, and delete entries from it.

Functions in List

Functions in List

List items can be accessed by using the index number, which is indexed:

fruits = ["strawberry", "mango", "date"]
print(fruits[1])

If you want to update the value of a certain item, look up the index number:

Change list item
fruits = ["strawberry", "mango", "date"]
fruits[1] = "apple"
print(fruits)

Use the append() function to add an item to the list’s end:

Append list
fruits = ["strawberry", "mango", "date"]
fruits.append("apple")
print(fruits)

The supplied item is removed using the remove() function.

fruits = ["strawberry", "mango", "date"]
fruits.remove("mango")
print(fruits)

Using a for loop, you may cycle through the entries on the list:

fruits = ["strawberry", "mango", "date"]
for x in fruits:
print(x)

To join the two lists we use + operator

aplha = ["a", "b", "c"]
numeric = [1, 2, 3]

final = aplha + numeric
print(final)

Let’s Wind up:

If you liked this Blog and found this blog informative do share with your friends and co-workers to help them. Till then keep Reading and Enjoying.

Contact us

If you are having any feedback or looking a way to connect with us.

Let’s connect together www.wakeupcoders.com/contact & think beyond everything.

Purnima Sinha (author), Narayan Jha (editor), Anjali Jha (digital marketing)

--

--

We make your business smarter and broader through the power of the internet. Researcher | Web developer | Internet of things | AI | www.wakeupcoders.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Wakeupcoders

We make your business smarter and broader through the power of the internet. Researcher | Web developer | Internet of things | AI | www.wakeupcoders.com