Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 18, 2019 18:12
Show Gist options
  • Save parzibyte/66dd97eee5174e0d059d3da0792f86dc to your computer and use it in GitHub Desktop.
Save parzibyte/66dd97eee5174e0d059d3da0792f86dc to your computer and use it in GitHub Desktop.
Validar entero en Python created by parzibyte - https://repl.it/@parzibyte/Validar-entero-en-Python
"""
Validar si una cadena o variable es un entero
en Python
@author parzibyte
"""
# Nota: la variable podría venir de cualquier lado, en
# este caso el usuario la escribe
posible_numero = input("Escribe algo y te diré si es un entero: ")
try:
entero = int(posible_numero)
print("Lo que escribiste es un entero")
except ValueError:
print("Lo que escribiste NO es un entero")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment