Python Program | Convert str to int in Python

int() is a built-in function used to convert string to integer in python. int() built-in function can be used to convert string object into integer in python.

Syntax

int(value, base)

value = number or string to be converted into integer object.
base = base of the number. for eg - 10.

Returns

int() function converts string, integer and floats into integer.

Let's look at an example:

#integer value
print("int(678) is:", int(678))
#float value
print("int(678.23) is:", int(678.23))
#string value
print("int('678') is:", int('678'))

Output

int(678) is: 678
int(678.23) is: 678
int('678') is: 678

Related Posts: