DEV Community

SATHISHKUMAR R
SATHISHKUMAR R

Posted on

What is List in Python?

A List in Python is a data type used to store multiple items in a single variable.

A list is created using square brackets [ ].

Lists can store different types of data, such as strings, integers, floats, and even other lists.

  1. Example of List: fruits = ["Apple", "Banana", "Mango"] print(fruits)

Output:
['Apple', 'Banana', 'Mango']

  1. Different Types of Lists:

String listnames = ["Sathish", "Raj", "Kumar"]

Integer listnumbers = [10, 20, 30, 40]

Mixed listdata = ["Sathish", 25, 5.5,True]

print(names)
print(numbers)
print(data)

  1. Accessing List Items (Indexing):

We can access list items using their index numbers.

fruits = ["Apple", "Banana","Mango"]
print(fruits[0])
print(fruits[1])
print(fruits[2])

Output:
Apple
Banana
Mango

Top comments (0)