Use int() function to convert a string to an integer.
Example Sum of two strings in Python
Simple example code calculates the sum of two given string numbers.
def sum_method(first, second): return int(first) + int(second) a = "100" b = "200" print(sum_method(a, b))
How do I sum two string inputs using Python?
Answer: Technically, you can’t perform a sum operation on a string input. However, you can join strings together to form a new string.
Simply store the two strings in a variable and combine them into a new variable.
string_1 = input("Enter first string: ") string_2 = input("Enter second string: ") res = string_1 + string_2 print(res)
Enter first string: Hello
Enter second string: Jo
Do comment if you have any doubts or suggestions on this Python string topic.
Note: IDE: PyCharm 2021.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.