DEV Community

Mukesh
Mukesh

Posted on

List in python

In python ,list is a ordered collection of multiple data types items stored in a single variable.

List also allows duplicate values and it is mutable.

Lists are written with square brackets [], and elements are accessed by their index starting at 0.

syntax:

fruits = ["apple", "banana", "cherry"]
mixed = [1, "hello", True, [2, 3]]

fruits, mixed are variable name.
[]-values are stored into the variable

How to print those values

To print the whole list use -print(fruits)

To print the exact required value -print(mixed[3][1]), those [] refers to the index position of the values.

Top comments (0)