Sitemap
Gaurav Verma

Gaurav Verma

Member-only story

Built-in Python Data Structure

4 min readAug 18, 2024
Press enter or click to view image in full size
Built-in Python Data structure

Data structure in any language provides ability to organize the data so that it can be accesses efficiently as and when required.

In Python we have below data structure.

  1. List: An ordered, mutable collection created using square brackets [].
    Example: lst = [1, 2, "Gaurav", 38.5, 'v']

List can be created using constructor i.e. list().
Example: lst = list((1, 2, "Gaurav", 38.5, 'v'))

##How to create list in python
lst = [1, 2, "Gaurav", "38.5", 'v']

##Create list in python using list's constructor
lstUsingConstrutor = list((1, 2, "Gaurav", 38.5, 'v'))

##How to create empty list in python
emptyLst = []

List element can be accessed by index. Starting index is 0 and last element index is (number of element in list-1).

Press enter or click to view image in full size
Access list element using index

2. Tuple: Similar to a list but immutable, created using parentheses ().
Example: tpl = ("Gaurav", "Verma", "Python")
Tuple can be created using constructor i.e. tuple().
Example: tpl= tuple(("Gaurav", "Verma", "Python"))

--

--