Skip to content

Instantly share code, notes, and snippets.

@joshenders
Created March 24, 2015 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshenders/421526ae868c0f4bea78 to your computer and use it in GitHub Desktop.
Save joshenders/421526ae868c0f4bea78 to your computer and use it in GitHub Desktop.
>>> a = "1.0"
>>> int(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.0'
>>> int(float(a))
1
>>> foo = "1.0"
>>> int(foo)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.0'
>>> int(float(foo))
1
>>> a = "1"
>>> int(a)
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment