June 4, 2024, 11 a.m. | Cristian Fernando

DEV Community dev.to


Explica este código Python




Dificultad: Fácil



my_tuple = (1, 2, True * 2, 3)
print(sum(my_tuple))


👉 A. 8

👉 B. 6

👉 C. 7

👉 D. SyntaxError



Respuesta:

👉 A. 8


Siempre y cuando todos los valores de la tupla sean números es posible usar la función sum(). En nuestro ejemplo True infiere a 1 y multiplicado por 2 lo sumamos con todos los demás valores de la tupla.


beginners python spanish sum true

Senior Machine Learning Engineer

@ GPTZero | Toronto, Canada

ML/AI Engineer / NLP Expert - Custom LLM Development (x/f/m)

@ HelloBetter | Remote

Senior Research Engineer/Specialist - Motor Mechanical Design

@ GKN Aerospace | Bristol, GB

Research Engineer (Motor Mechanical Design)

@ GKN Aerospace | Bristol, GB

Senior Research Engineer (Electromagnetic Design)

@ GKN Aerospace | Bristol, GB

Associate Research Engineer Clubs | Titleist

@ Acushnet Company | Carlsbad, CA, United States