how to make a tuplet in python code example

Example 1: changing tuple values

x = ("apple", "banana", "cherry")
y = list(x)
y[1] = "kiwi"
x = tuple(y)

print(x)

Example 2: tuple() python

example = [1, 2, 3, 4]
# Here is a list above! As we both know, lists can change in value
# unlike toples, which are not using [] but () instead and cannot
# change in value, because their values are static.

# list() converts your tuple into a list.
tupleexample = ('a', 'b', 'c')

print(list(tupleexample))

>> ['a', 'b', 'c']

# tuple() does the same thing, but converts your list into a tuple instead.

print(example)

>> [1, 2, 3, 4]

print(tuple(example))

>> (1, 2, 3, 4)

Tags:

C Example