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)
Answers:
Just call the functions in a single line as
lineNumStr = str(int(lineNumStr)+1)
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)
Just call the functions in a single line as
lineNumStr = str(int(lineNumStr)+1)