Python List – Python Programming

What is Python List and how to use it.
Photo by Suzy Hazelwood from Pexels

Python List are very similar to Array. List can store different datatype elements. A list contains things separated by commas and capsulate inside square brackets ([ ]). List is a data type of collection of data which is ordered and changeable. List also allows duplicate members.

Features of Python Lists

  1. Ordered Lists
  2. Can change values after declaring elements
  3. Allow duplicate members
  4. Uses Brackets [ ]
  5. Can store different datatypes

Declaring List in Python

list1 = ['Study', 123, 1.25, 'Gyaan', 456]
list2 = ['Huzaif', 789]
print(list1)
print(list2)

Note – The plus (+) sign is the concatenation operator and the asterisk (*) is the repetition Operator. For example −

list1 = ['Study', 123, 1.25, 'Gyaan', 456]
list2 = ['Huzaif', 789]

print(list1)
print(list1[0])
print(list1[0:3])
print(list1[2:])
print(list2*2)
print(list1+list2)

It will produce output like this

>>> print(list1)
 ['Study', 123, 1.25, 'Gyaan', 456]
>>> print(list1[0])
 Study
>>> print(list1[0:3])
 ['Study', 123, 1.25]
>>> print(list1[2:])
 [1.25, 'Gyaan', 456]
>>> print(list2*2)
 ['Huzaif', 789, 'Huzaif', 789]
>>> print(list1+list2)
 ['Study', 123, 1.25, 'Gyaan', 456, 'Huzaif', 789]
Python Lists Video Tutorial

Whats Next – Python Tuple

Share