+2 votes
in Programming Languages by (71.8k 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

+2 votes
by (71.8k points)
selected by
 
Best answer

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
24
>>> eval('23')+2
25
>>> str(23)
'23'

 


...