+2 votes
in Programming Languages by (11k 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 (11k 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
24
>>> eval('23')+2
25
>>> str(23)
'23'

 

Related questions

...