-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtuples_sets.py
49 lines (32 loc) · 851 Bytes
/
tuples_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
# A Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
# Create tuple
fruits = ('Apples', 'Oranges', 'Grapes')
fruits = ['Apples', 'Oranges', 'Grapes', 'Pears']
# Using a constructor
# fruits2 = tuple(('Apples', 'Oranges', 'Grapes'))
# Single value needs trailing comma
fruits2 = ('Apples',)
# Get value
print(fruits[1])
# Can't change value
fruits[0] = 'Pears'
# Delete tuple
del fruits2
# Get length
print(len(fruits))
# A Set is a collection which is unordered and unindexed. No duplicate members.
# Create set
fruits_set = {'Apples', 'Oranges', 'Mango'}
# Check if in set
print('Apples' in fruits_set)
# Add to set
fruits_set.add('Grape')
# Remove from set
fruits_set.remove('Grape')
# Add duplicate
fruits_set.add('Apples')
# Clear set
fruits_set.clear()
# Delete
del fruits_set
print(fruits_set)