Skip to content

Instantly share code, notes, and snippets.

@krid78
Created May 4, 2016 06:41
Show Gist options
  • Save krid78/066a7509244b3ea59cf0cc2825df38c4 to your computer and use it in GitHub Desktop.
Save krid78/066a7509244b3ea59cf0cc2825df38c4 to your computer and use it in GitHub Desktop.
return correct type for value in python
def type_set(val):
"""
return the value with its correct type
default type of return value is str
:val: input value of any type
:return: same value, correct type
"""
try:
return int(val)
except ValueError:
pass
try:
return float(val)
except ValueError:
pass
return str(val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment