Number String converting to INT,adding to it, and back to string

Question:

I would like to know if there is a more efficient way in Python, to
convert a number string to an integer, add to it and then put it back as a string?

This is what I am currently doing and it works, it just seems a waste to have to create this interim variable.

lineNumStr = '1'
lineNum = int(lineNumStr)
lineNum += 1
lineNumStr = str(lineNum)
Asked By: user3615938

||

Answers:

Just call the functions in a single line as

lineNumStr = str(int(lineNumStr)+1)
Answered By: anirudh
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.