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

Write a function named first_number that takes a string as an argument. The function should search, with a regular expre

Write a function named first_number that takes a string as an argument. The function should search, with a regular expression, the first number in the string and return the match object.

syntax error, please help =)

escapes.py
import re
def first_number("rock3"):
  re.search(r'\d')
  return str(first_number)

3 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hey, Michaelangelo, couple problems here

  • when defining a function, you shouldn't manually pass in an actual string as function parameter.
  • re.search takes a second argument.
def first_number(s):
  return re.search(r'\d', s)
Ryan Hartigan
Ryan Hartigan
3,425 Points

This is my first time going through Python. Nowhere in the Track up to this point have they mentioned a "def" function or how to define function parameters - the idea that there isn't a "Show Answer" button when the student has not been given enough information to solve the problem properly, is mind-boggling.

Hello Ryan,

I presume you took the Django Track, This track is taught with an assumption that you've covered Python Basics Course already.

Cheryl Hughey
Cheryl Hughey
8,770 Points

I agree. Since Treehouse has moved to teaching User Experience, I really think they need to revisit their decision not to use a "Show Answer" feature. Assuming a student has taken and understood a previous course doesn't help the buy-in for retainment.

There is a lot of that. You'll see stuff in the solution for most of these that they have never gone over before. To be fair, it doesn't seem like just a Treehouse problem.

You are right my friend. There really was no build up to this.

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