The int function
The int function creates a new number from the original object. In the first parameter, we specify the object from which we will make a number. In the second optional parameter, you can specify the number format (by default, 10).
Syntax
int(number or string, [number format])
Example
Let's use the int function to make a number out of a string:
txt = '123'
num = int(txt)
print(num)
Result of code execution:
123
Example
Now let's convert the string value into an octal number:
txt = '0o12'
num = int(txt, base=8)
print(num)
Result of code execution:
10