What Is the Difference Between Tuples and List?

Timothy Joseph | January 18, 2021

What Is the Difference Between Tuples and List?

Web app services are now focused now on Python as it is easy to do numerical calculations in scientific-related applications.

There are two types of data structures in Python i.e. Lists and Tuples.

Both are different in their working as listed below:

  1. A List is a group of comma separated values in square brackets and have similar data types.

    The content in the list are mutable and any change can be performed once after the List Object is created.

    E.g., i= [1,2, 3, 4, 5, 6]

    It is used if the group of data doesn’t need random access and frequent data modification is required.

  2. A Tuple is a group of Comma Separated Values enclosed in round brackets or parenthesis. The contents in the list are immutable and change cannot be performed once after the List Object is created.

    e.g., t = (10, 20, 30, 40)

    t[1]=35 will return the unsupported item assignment as ValueError

It is combined with dictionary to represent a key and when the data doesn’t require modification.

Disclaimer

This publication is for informational purposes only, and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.

Post a Comment