DEV Community

Cover image for Ibuprofeno.py💊| #189: Explica este código Python
Cristian Fernando
Cristian Fernando

Posted on

1

Ibuprofeno.py💊| #189: Explica este código Python

Explica este código Python

Dificultad: Fácil

def f(a:int, b:int)->int:
    return a + b

print(f("1", "2"))
Enter fullscreen mode Exit fullscreen mode
  • A. 12
  • B. 3
  • C. Error
  • D. 21

Respuesta:

👉 A. 12

Desde Python 3.5 se agrego una característica denominada anotaciones de tipos. Consiste en poder agregar el tipo de dato a variables y parámetros de función y también el tipo del valor de retorno de una función.

Esta peculiaridad solamente es nominal, osea que no marcara error cuando no cumplamos la anotación de tipo, solo sirve para documentar nuestro código de manera sencilla pero sin agregar ninguna funcionalidad extra.

En nuestro ejemplo pese a que especificamos que los parámetros deben ser enteros, al llamar a la función y pasarle cadenas no habría problema, pero visualmente ya podemos ver que algo anda mal en el código pese a que funciona.

💡 One last tip before you go

Tired of spending so much on your side projects? 😒

Take advantage of early-bird pricing ❤️

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay