
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
List vs tuple vs dictionary in Python
List and Tuple objects are sequences. A dictionary is a hash table of key-value pairs. List and tuple is an ordered collection of items. Dictionary is unordered collection.
List and dictionary objects are mutable i.e. it is possible to add new item or delete and item from it. Tuple is an immutable object. Addition or deletion operations are not possible on tuple object.
Each of them is a collection of comma-separated items. List items are enclosed in square brackets [], tuple items in round brackets or parentheses (), and dictionary items in curly brackets {}
>>> L1=[12, "Ravi", "B.Com FY", 78.50] #list >>> T1=(12, "Ravi", "B.Com FY", 78.50)#tuple >>> D1={"Rollno":12, "class":"B.com FY", "precentage":78.50}#dictionary
List and tuple items are indexed. Slice operator allows item of certain index to be accessed
>>> print (L1[2]) B.Com FY >>> print (T1[2]) B.Com FY
Items in dictionary are not indexed. Value associated with a certain key is obtained by putting in square bracket. The get() method of dictionary also returns associated value.
>>> print (D1['class']) B.com FY >>> print (D1.get('class')) B.com FY
- Related Articles
- Difference Between Set vs List vs Tuple
- Hashtable vs. Dictionary in C#
- Dictionary to list of tuple conversion in Python
- C++ vs Java vs Python?
- Cplus plus vs Java vs Python?
- Difference between \'__eq__\' VS \'is\' VS \'==\' in Python
- Add dictionary to tuple in Python
- str() vs repr() in Python?
- Virtual vs Sealed vs New vs Abstract in C#
- PoC vs Prototype vs MVP vs Pilot in Agile
- Python – Concatenate Tuple to Dictionary Key
- Python - fabs() vs abs()
- Explain Python vs Scala
- Convert tuple to adjacent pair dictionary in Python
- R vs Python in Data Science
