0
nextt[0:1] = "*2"

rds = int(nextt[0:1].replace("*",""))

And there is problem, it says:ValueError: invalid literal for int() with base 10: ''

I just need to delete "*" from string and convert it to int.

1
  • What type is nextt to allow for string slice assignment here? Or are you merely illustrating what you think nextt contains after slicing? Commented Dec 15, 2013 at 16:38

2 Answers 2

4

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])
Sign up to request clarification or add additional context in comments.

Comments

1
 int('*2'.replace('*', ''))
  1. '*2'.replace('*', '') this replaces * with empty string and results in '2'

  2. Now you cast it to int.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.