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:
pythontxt1 = '1'
txt2 = '2'
res = int(txt1) + int(txt2)
print(res) # the number 3
You can use the conversion command directly in the function call:
pythonprint(int('123')) # the number 123
Задание 1
Given a variable:
pythontxt = '123'
Convert the variable value to an integer.
Задание 2
Given variables:
pythontxt1 = '123'
txt2 = '456'
Find the sum of the values of these variables.