What are Python’s data structures? explain with example.
What are Python’s data structures? explain with example.
Student
The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
Python provides several built-in data structures, and it also allows you to create custom ones. These are mainly divided into primitive and non-primitive (collection) data structures.
1. Primitive Data Structures
These are the most basic types:
10,-3)3.14,-2.5)3+4j)True,False)"hello",'Python')2. Non-Primitive (Collections) Data Structures
These are used to store multiple values.
a. List
Ordered, mutable, allows duplicates.
Example:
b. Tuple
Ordered, immutable, allows duplicates.
Example:
c. Set
Unordered, mutable, does not allow duplicates.
Example:
d. Dictionary (dict)
Unordered (insertion-ordered since Python 3.7), mutable, stores key–value pairs.
Example:
3. Specialized Data Structures (from
collectionsmodule)4. User-Defined Data Structures
You can also implement:
deque)dequeorqueue.Queue)In short:
list,tuple,set,dictdeque,Counter,defaultdict, etc.