Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Regular Expressions in Python Introduction to Regular Expressions Escapes

Sathya Musanipalli
Sathya Musanipalli
2,265 Points

Keep getting syntax error. What am I doing wrong in passing string as an argument to the function?

How do I pass the string without getting a syntax error?

escapes.py
import re

def first_number('string'):
    return(re.search(r'\d', first_number))

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hey Sathya Musanipalli 👋

You'll want to have a look at your argument name as well as using it in your return statement. Currently, your argument is wrapped in backticks making it an actual string while you want it to be a variable that holds the value you'll be passing to the function when it's being called.

In the return statement you'll then want to use this argument to check for numbers instead of the function name.

After these changes your code should look something like this:

import re

def first_number(string):
    return(re.search(r'\d', string))

This should then pass the challenge as expected 🙂

Hope this helps! Happy Coding! 🧑‍💻