Python has four main collection data types: lists, tuples, sets, and dictionaries. Each has different characteristics that make them useful for different purposes. Here's a brief overview of each:
1.Lists: Lists are ordered collections of items that can be changed (mutable). This means you can add, remove, or modify items in a list. Lists are created using square brackets and commas to separate items. For example:
my_list = [1, 2, 3, 4]
2.Tuples: Tuples are similar to lists, but they are immutable. Once created, you cannot change them. Tuples are created using parentheses and commas to separate items. For example:
my_tuple = (1, 2, 3, 4)
3.Sets: Sets are unordered collections of unique items. They cannot contain duplicates. Sets are created using curly braces or the set() function. For example:
my_set = {1, 2, 3, 4}
my_set = set([1, 2, 3, 4])
4.Dictionaries: Dictionaries are unordered collections of key-value pairs. Each key in a dictionary must be unique, and the keys are used to access the corresponding values. Dictionaries are created using curly braces and colons to separate key-value pairs. For example:
my_dict = {'apple': 1, 'banana': 2, 'orange': 3}
To summarize, lists and tuples are ordered collections that differ in their mutability, with lists being mutable and tuples being immutable. Sets and dictionaries are unordered collections, with sets containing only unique items and dictionaries consisting of key-value pairs.