-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path072-Create-Set.py
More file actions
80 lines (64 loc) · 2.74 KB
/
Copy path072-Create-Set.py
File metadata and controls
80 lines (64 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
===============================================================================
File Name : 72-Create-Set.py
Description : Create a Set in Python
Author : Shaik Mahaboob Basha
===============================================================================
Definition:
A set is a built-in collection data type used to store multiple unique values.
Sets are unordered, mutable, and do not allow duplicate elements.
Syntax:
set_name = {value1, value2, value3}
Example:
numbers = {10, 20, 30}
"""
# -----------------------------------------------------------------------------
# Creating a set of integers.
# -----------------------------------------------------------------------------
numbers = {10, 20, 30, 40, 50}
# -----------------------------------------------------------------------------
# Displaying the integer set.
# -----------------------------------------------------------------------------
print("Integer Set :", numbers)
# Output:
# Integer Set : {10, 20, 30, 40, 50}
print()
# -----------------------------------------------------------------------------
# Creating a set of strings.
# -----------------------------------------------------------------------------
fruits = {"Apple", "Banana", "Mango", "Orange"}
# -----------------------------------------------------------------------------
# Displaying the string set.
# -----------------------------------------------------------------------------
print("Fruit Set :", fruits)
# Output:
# Fruit Set : {'Apple', 'Banana', 'Mango', 'Orange'}
print()
# -----------------------------------------------------------------------------
# Creating a mixed data type set.
# -----------------------------------------------------------------------------
student = {101, "Rahul", 92.5, True}
# -----------------------------------------------------------------------------
# Displaying the mixed data type set.
# -----------------------------------------------------------------------------
print("Mixed Set :", student)
# Output:
# Mixed Set : {101, 'Rahul', 92.5, True}
print()
# -----------------------------------------------------------------------------
# Creating an empty set.
# -----------------------------------------------------------------------------
empty_set = set()
# -----------------------------------------------------------------------------
# Displaying the empty set.
# -----------------------------------------------------------------------------
print("Empty Set :", empty_set)
# Output:
# Empty Set : set()
print()
# -----------------------------------------------------------------------------
# Displaying the type of the set.
# -----------------------------------------------------------------------------
print("Type of numbers :", type(numbers))
# Output:
# Type of numbers : <class 'set'>