Answers for "what is a tuple in python"

0

create tuples python

values = [a, b, c, 1, 2, 3]

values = tuple(values)

print(values)
Posted by: Guest on December-15-2020
2

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'>
Posted by: Guest on October-12-2020
2

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])
Posted by: Guest on March-04-2021
4

tuple in python

#a tuple is basically the same thing as a
#list, except that it can not be modified.
tup = ('a','b','c')
Posted by: Guest on March-14-2020
0

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.
Posted by: Guest on September-05-2021
0

tuplein python

a=(1,2,3,4)
print(a[-3])
Posted by: Guest on July-09-2021

Python Answers by Framework

Browse Popular Code Answers by Language