create tuples python
values = [a, b, c, 1, 2, 3]
values = tuple(values)
print(values)
create tuples python
values = [a, b, c, 1, 2, 3]
values = tuple(values)
print(values)
tuples in python
my_tuple = ("hello")
print(type(my_tuple)) # <class 'str'>
# Creating a tuple having one element
my_tuple = ("hello",)
print(type(my_tuple)) # <class 'tuple'>
# Parentheses is optional
my_tuple = "hello",
print(type(my_tuple)) # <class 'tuple'>
tuples in python
t = 12345, 54321, 'hello!'
print(t[0])
# output 12345
print(t)
# output (12345, 54321, 'hello!')
# Tuples may be nested:
u = t, (1, 2, 3, 4, 5)
print(u)
# output ((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))
# Tuples are immutable:
# assigning value of 12345 to 88888
t[0] = 88888
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
# but they can contain mutable objects:
v = ([1, 2, 3], [3, 2, 1])
print(v)
# output ([1, 2, 3], [3, 2, 1])
tuple in python
#a tuple is basically the same thing as a
#list, except that it can not be modified.
tup = ('a','b','c')
ways to create tuple in python
# There are more ways to create a TUPLE in Python.
# First of all, a TUPLE is usually created by:
# (STEP 1) creating a Parethesis ()
# (STEP 2) putting a value in Parenthesis. Example: (3)
# (STEP 3) putting more value by adding Comma. Example: (3, 4)
# (STEP 4) Repeat Step 3 if u want to add more value. Example: (3, 4, coffee)
# That's how to create TUPLE
# EXAMPLE
adsdfawea = (123, 56.3, 'cheese')
# But did you know, you can create TUPLE without any value inside the () ???
wallet = ()
print(type(wallet))
# But did you know, you can create TUPLE without parenthesis () ???
plate = 'cake',
print(type(plate))
# As you can see, STRING is possible in TUPLE, not just INTEGERS or FLOATS.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us