Convert String to Int in Python
Last modified: 2023-08-29
Conversion
String (Number) -> Int
For strings representing numbers, we can just use int
method in Python.
int("123")
# 123
String (Text) -> Int
For strings representing characters, we need to convert each character to Unicode at first.
Then concatenate these unicoded string.
text = "Hello"
numbers_str = ""
for t in text:
numbers_str += str(ord(t))
print(int(decimal_str))
# 72101108108111