Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
nextt[0:1] = "*2" rds = int(nextt[0:1].replace("*",""))
And there is problem, it says:ValueError: invalid literal for int() with base 10: ''
ValueError: invalid literal for int() with base 10: ''
I just need to delete "*" from string and convert it to int.
nextt
You are slicing just one character:
>>> '*2foo'[0:1] '*'
Replacing the * gives you an empty string. Perhaps you wanted to slice two characters?
*
>>> '*2foo'[:2] '*2'
If you are slicing anyway, just pick the digit character without the *:
int(nextt[1])
Add a comment
int('*2'.replace('*', ''))
'*2'.replace('*', '') this replaces * with empty string and results in '2'
'*2'.replace('*', '')
Now you cast it to int.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
nexttto allow for string slice assignment here? Or are you merely illustrating what you thinknexttcontains after slicing?