Converting to Integers in Python
To convert a string to a number, you need to use the int function. Let's make two string variables numeric and get their sum:
txt1 = '1'
txt2 = '2'
res = int(txt1) + int(txt2)
print(res) # the number 3
You can use the conversion command directly in the function call:
print(int('123')) # the number 123
Given a variable:
txt = '123'
Convert the variable value to an integer.
Given variables:
txt1 = '123'
txt2 = '456'
Find the sum of the values of these variables.