-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path38_Python_Sets.py
61 lines (45 loc) · 1.07 KB
/
38_Python_Sets.py
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
# Python - Sets
print("Python - Sets:")
# Creating a set
print("\nCreating a set:")
set1 = {'a', 'b', 'c'}
print(set1)
# Duplicate values in a set will be ignored
print("\nDuplicate values in a set will be ignored:")
set2 = {True, True, False}
print(set2)
# True and 1 is considered same value in set
print("\nTrue and 1 is considered the same value:")
set3 = {'apple', True, 1, 5}
print(set3)
# Get length of a set
print("\nGet length of a set:")
set4 = {1, 4, 7, 3, 6, 9, 15, 22, 30, 99}
print(len(set4))
# Set items - Data types
print("\nSet items - Data types:")
# int
print("int")
set5 = {1, 2, 3, 4, 5}
print(set5)
# string
print("string")
set6 = {'apple', 'mango', 'orange'}
print(set6)
# boolean
print("boolean")
set7 = {True, True, False}
print(set7)
# mix data types
print("mix data types")
set8 = {2, 'apple', True, 9, False, 'orange'}
print(set8)
# Get the type
print("\nGet the type:")
set9 = {'toyota', 'nissan', 'volvo'}
print(type(set9))
# The set() constructor
print("\nThe set() constructor:")
set10 = set((3, 'test', False))
print(set10)
print(type(set10))