Quick Enquiry Form

×

    EnquiryEnquire Now

    Quick Enquiry

      List vs Tuple: Difference Between List and Tuple

      list vs tuple
      Blog

      List vs Tuple: Difference Between List and Tuple

      Introduction

      Python has four basic inbuilt data structures, which are Dictionary, Tuple, Lists, and Set. Lists and tuples, which are data structures used in Python, have significant differences between them. These differences make them stand apart and are helpful in using them in appropriate situations. Both lists and tuples hold python objects, which are separated by commas. They vary in declaration, mutability, time, memory consumption etc.

      What are Tuples and Lists?

      Data structures are used in Python. Tuples and lists are a type of data structure in Python. Both tuples and lists store data in a single variable. The difference is that tuples store the data in a variable enclosed within square brackets whereas lists store data within parentheses. Tuples and lists are used to store multiple values. Lists are more dynamic and tuples are more static.

      On further reading, you will find out Tuple Vs List key differences.

      1. Syntax (Tuple Vs List)

      There is a difference in the way tuples and lists are declared in Python.

      Tuple: Data is stored in a variable enclosed within parentheses.

      Eg: tup1 = (1,2,3,4)
      print(tup1)
      Output: (1,2,3,4)

      Explanation

      Here in the above example, we can see that the variable “tup1” holds the data “1,2,3,4” enclosed within parentheses. When we use the print statement to print this tuple, the output is (1,2,3,4).

      List: Data is stored in a variable enclosed within square brackets Eg: lis1 = [5,6,7,8] print(lis1)

      Output : [5,6,7,8]


      Explanation

      Here in the above example, we can see that the variable “lis1” holds the data “5,6,7,8” enclosed within square brackets. When we use the print statement to print this list, the output is [5,6,7,8].

      1
      Softlogic-Academy