Saltar al contenido

cómo acceder a tuplas ejemplo de código de Python

Tenemos el arreglo a este asunto, o por lo menos eso pensamos. Si tienes inquietudes puedes escribirlo en el apartado de preguntas, que sin dudarlo te ayudaremos

Ejemplo 1: tuplas en python

t =12345,54321,'hello!'print(t[0])#output12345print(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:#assigningvalue of 12345 to 88888
t[0]=88888Traceback(most recent call last):
  File "", line 1, in <module>
TypeError:'tuple' object does not support item assignment
#butthey can contain mutable objects:
v =([1,2,3],[3,2,1])print(v)#output([1,2,3],[3,2,1])

Ejemplo 2: tuplas en 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'>

Ejemplo 3: que son las tuplas en Python

#A tuple is essentailly a list with limited uses. They are popular when making variables #orcontainers that you don't want changed, or when making temporary variables.#A tuple is defined with parentheses.

Ejemplo 4: tuplas en python

#thetuples are like the Read-Only they are not to be changed or modified they're constant

letters ="a","b","c","d"    # you can use() as they are optional
print(letters)"""
    tuples are immutable but it's important because they don't returns the bugs
    
    these are sequence types means you can iterate over them by it's index numbers
    
    tuples data can't be changed but list's data can be changed
"""

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)


Tags : /

Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *