Skip to content

Instantly share code, notes, and snippets.

@ychoi-kr
Last active May 19, 2021 04:10
Show Gist options
  • Save ychoi-kr/cf61a7da0ae064439f5fa9bbb00773ce to your computer and use it in GitHub Desktop.
Save ychoi-kr/cf61a7da0ae064439f5fa9bbb00773ce to your computer and use it in GitHub Desktop.
simple type inference with try-except in python
>>> def triple_input_number():
... x = input()
... try:
... n = int(x)
... return n * 3
... except:
... pass
...
>>> triple_input_number()
3
9
>>> triple_input_number()
a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment