Data Structure is a core concept of computer science by which we can do programming in any other progrmming languages. Data structure are used to store the data elements in a sequential manner.
In Python we can call Data Structure as Collections. Collections are containers that are used to store collections of data.
- Tuple
- Set
- List
- Dictionary
A tuple is a collection of objects which ordered and immutable. Tuples are sequences, just like lists. The differences between tuples and lists are mutable, the tuples are immutable it means cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.You can access tuple items by referring to the index number, inside square brackets.
A set is an unordered collection of items. Every set element is unique and must be immutable it means cannot be changed. The sets remove the duplicate items. There is no index attached to the elements of the set, i.e., we cannot directly access any element of the set by the index. We can print them all together, or we can get the list of elements by looping through the set. A set is created by placing all the items (elements) inside curly braces {}, separated by comma.
A List is used to store the sequence of various types of data. Data are inclosed inside [ ] brackets seprated by commas(,). Lists are mutable in nature it means data which can be changed when required. Duplicate entries are allowed in list. A list can also have another list as an item. This is called a nested list.
A dictionaries can be defined as an unordered collection of key-value pairs separated by (:) and enclosed in ({}) braces. The key should be unique and can be of any data type. Keys are used to access elements in dictionary just like index in List. Dictionaries are mutable. i.e. it is possible to add, modify, delete key-value pairs.