Set:
- The set data type is used to store unique values and displayed by ordered sequence manner.
- These items are mutable, that means can change the sets.
- It is denoted by curly braces {} but if calling the index with value means not possible.
Set:
Syntax:
Declaring value into the set:
Variable_name={item1,item2,...item n}
Example:
a={1000,’Kurshitha’,’female’,450}
Example program for print the set of elements:
a={8,5,1,3,7}
print(a)
Output:
Insert an item into the set:
a={8,5,1,3,7}
a.add(15)
print(a)
Output:
Insert number of items at a time into the set:
a={8,5,1,3,7}
a.update([15,10,11])
print(a)
Output:
No comments:
Post a Comment