#๐ Replacing numbers
22 messages ยท Page 1 of 1 (latest)
@austere robin
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Heya @austere robin ๐
You're probably looking at re.sub() or str.replace() (renamed as Reptile's examples are better :P)
If you can give some examples of what needs to be done..?
Uh, depends on what you mean by "replace a certain number of digits/numbers", but str.replace and re.sub come to mind.
I've been trying to use something like this: r = r.replace([:S])

I'm not sure what that's meant to mean, but replace has an argument to limit the max number of replacements, if that's what you want.
!d str.replace
str.replace(old, new[, count])```
Return a copy of the string with all occurrences of substring *old* replaced by *new*. If the optional argument *count* is given, only the first *count* occurrences are replaced.
I don't think replace is actually what you want
You are just trying to remove a beginning part?
yeah, but I don't know which code to use
um I still don't really get it
like this? R1 = slice(r[:S])
The colon notation in [] is a slice (when used as getitem)
And you need to flip it around: the stop value should be the start value
so like this? r = r.replace([S:])
Try to not guess
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.