+2 votes
in Programming Languages by (20.3k points)
Suppose I have digits in char/string format e.g. '23' , '10' etc. How can I convert it to integer for arithmetic operations?

1 Answer

0 votes
by (20.3k points)

You can use either built-in eval function or int function to convert char/string to integer to do arithmetic operations. Also, you can use str function to convert the numeric result back to string.

>>> int('22')+2
>>> eval('23')+2
>>> str(23)


Related questions