Python int() built-in function

From the Python 3 documentation

Return an integer object constructed from a number or string x, or return 0 if no arguments are given.

Examples

>>> # transform a string to an integer
>>> from_integer = int('29')
>>> from_integer
# 29
>>> type(from_integer)
# <class 'int'>

>>> # transform a float to integer
>>> from_float = int(-3.14)
>>> from_float
# -3
>>> type(from_float)
# <class 'int'>

>>> # return an empty string
>>> int()
# 0

Subscribe to pythoncheatsheet.org

Join 10.900+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.