1my_tuple = ("hello")
2print(type(my_tuple)) # <class 'str'>
3
4# Creating a tuple having one element
5my_tuple = ("hello",)
6print(type(my_tuple)) # <class 'tuple'>
7
8# Parentheses is optional
9my_tuple = "hello",
10print(type(my_tuple)) # <class 'tuple'>
1#a tuple is basically the same thing as a
2#list, except that it can not be modified.
3tup = ('a','b','c')
1example = [1, 2, 3, 4]
2# Here is a list above! As we both know, lists can change in value
3# unlike toples, which are not using [] but () instead and cannot
4# change in value, because their values are static.
5
6# list() converts your tuple into a list.
7tupleexample = ('a', 'b', 'c')
8
9print(list(tupleexample))
10
11>> ['a', 'b', 'c']
12
13# tuple() does the same thing, but converts your list into a tuple instead.
14
15print(example)
16
17>> [1, 2, 3, 4]
18
19print(tuple(example))
20
21>> (1, 2, 3, 4)
1# Let's have a look here first.
2coffee = (3.14,) # coffee is a VARIABLE, 3.14 is a FLOAT NUMBER
3
4# What is the TYPE inside the VARIABLE coffee?
5
6#Let's see
7print(type(coffee)) #It will print what TYPE the VARIABLE it is
8
9# It will print: <class 'tuple'>
10
11
12
13# Why it printed <class 'tuple'> and not <class 'float'>???
14
15
16# ANSWER: #
17
18# Because we put the comma --> , <-- after the 3.14
19# That's why it became a tuple type. (not a float type)
20
21
22# HOW TO CREATE a TUPLE?
23
24# To create a tuple, create a Parenthesis --> () <--
25# Then add value inside, for example I add 4 inside the parenthesis --> (4) <--
26# Last, add comma --> , <-- like this --> (4,) <--
27# Then add more like this --> (4, 5) <--
28# If you want to add more, just use --> , <-- like this --> (4, 5, 6) <--
29
30
31# Wait, I don't understand, what's the purpose of TUPLE?
32# it let you store an ordered sequence of items.
33# It's similar to LIST but data inside the TUPLE can't be change.
34
35# NOTES
36# STRING is also possible in TUPLE
37food = ('cake', 'cupcake', 1997, 2000);
38# As you can see, the 'cake' and 'cupcake' are STRINGS, while 1997 and 2000 are INTEGER NUMBERS.