Python provides builtin functions that explicitly convert between data types. This is commonly known as casting. It is often necessary to cast values when they are used as arguments in a function call. It is generally necessary to cast values whenever a function or other process cannot implicitly convert a given variable to the appropriate datatype. For example when printing a string followed by a numeric type the numeric type must be cast to a string for string concatenation in the print() call to work.
int(variable) is used to cast values to integers. Casting a float to an int will disregard its decimal places. Casting a string to int will convert numeric strings like "123" to integer values like 123.
my_var = 16.05
int(my_var)
my_string = "1605"
int(my_string, 10)
int(value, base)
value : a numeric or string-numeric value
base : optional integer to indicate base of numeric-string value (default is base 10)
code.py output:
16
1605