-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuples.py
23 lines (20 loc) · 838 Bytes
/
tuples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Creating a Tuple
this_tuple = ("apple", "banana", "cherry")
print("A simple tuple")
print(this_tuple) # Returns ('apple', 'banana', 'cherry')
print("------------------------------------")
# Getting the item in position 1
this_tuple = ("apple", "banana", "cherry")
print("Getting the item in position 1")
print(this_tuple[1]) # Returns banana
print("------------------------------------")
# Using the tuple() Constructor
this_tuple = tuple(("apple", "banana", "cherry")) # note the double round-brackets
print("Using the tuple() Constructor")
print(this_tuple) # Returns ('apple', 'banana', 'cherry')
print("------------------------------------")
# Length of the tuple
this_tuple = tuple(("apple", "banana", "cherry"))
print("Length of the tuple")
print(len(this_tuple)) # Returns 3
print("------------------------------------")