How to Convert a Python String to an Int and an Int to a String?

String → Integer:

s = "42"
i = int(s)
# i == 42

Integer → String:

i = 42
s = str(i)
# s == "42"

Leave a Comment

Your email address will not be published. Required fields are marked *