0

I'm trying to get the following code to print out the numbers of that string but it doesn't print anything.could someone please help a beginner coder out.

import re
def remove_letters(provided_string):
    provided_string="adf73390sdkfjh"
    new_string =  re.sub("[^0-9]", "", provided_string)
    return (new_string)
2
  • 3
    Is this all the code? You never call the function and never print anything. Please show a minimal reproducible example. Commented Aug 25, 2020 at 16:58
  • 3
    Seems to work for me. The argument you provide is never used though, and always overwritten by your hard-coded string. Commented Aug 25, 2020 at 16:59

1 Answer 1

2

Are you sure you are calling the function? This seems to work fine.

import re

def remove_letters(provided_string):
    new_string = re.sub("[^0-9]", "", provided_string)
    return new_string

print(remove_letters("adf73390sdkfjh"))
Sign up to request clarification or add additional context in comments.

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.