Skip to content

Commit 5419eaa

Browse files
authored
Tuple and Set data type
A tuple is a collection of ordered and immutable elements, enclosed in parentheses (). It is similar to a list, but its elements cannot be modified after creation. 1. Tuples can contain elements of different data types, including numbers, strings, and even other tuples. 2. Tuples are immutable, which means you cannot change the elements once they are defined. However, you can create a new tuple by concatenating two or more tuples. 3. Tuples are indexed, meaning that you can access individual elements by their position in the tuple, starting from 0. 4. Tuples can be used as keys in dictionaries since they are immutable. 5. Tuples can be used to return multiple values from a function. 6. Tuples are faster than lists for accessing and iterating over elements, but slower when it comes to adding, removing, or modifying elements. ---------------------------------------------------------------------------------------------------------------------------------------------------------------- Set- A set is an unordered collection of unique elements. It is a built-in data type that is used to store a collection of items, such as numbers, strings, or other objects 1. Sets are defined using curly braces { } or using the built-in set() function. 2. Sets do not have any duplicate elements. If you add a duplicate element to a set, it will be ignored. 3. Sets are mutable, which means you can add or remove elements after creation. 4. Sets can contain elements of different data types, but all the elements must be immutable. 5. Sets are unordered, which means that the elements are not stored in any particular order. 6. You can perform various set operations, such as union, intersection, and difference, using built-in methods. Sets can be useful in many different scenarios, such as removing duplicates from a list or checking for the existence of certain elements in a collection.
1 parent f387f93 commit 5419eaa

File tree

1 file changed

+1183
-0
lines changed

1 file changed

+1183
-0
lines changed

0 commit comments

Comments
 (0)