As the others said, you have a semantic problem on your indentation, but you don't have to write such function to do that, a more pythonic way to do that is:
def get_digits(text):
return filter(str.isdigit, text)
On the interpreter:
>>> filter(str.isdigit, "lol123")
'123'
Some advice
Always test things yourself when people shows 'faster' methods:
from timeit import Timer
def get_digits1(text):
c = ""
for i in text:
if i.isdigit():
c += i
return c
def get_digits2(text):
return filter(str.isdigit, text)
def get_digits3(text):
return ''.join(c for c in text if c.isdigit())
if __name__ == '__main__':
count = 5000000
t = Timer("get_digits1('abcdef123456789ghijklmnopq123456789')", "from __main__ import get_digits1")
print t.timeit(number=count)
t = Timer("get_digits2('abcdef123456789ghijklmnopq123456789')", "from __main__ import get_digits2")
print t.timeit(number=count)
t = Timer("get_digits3('abcdef123456789ghijklmnopq123456789')", "from __main__ import get_digits3")
print t.timeit(number=count)
~# python tit.py
19.990989106 # Your original solution
16.7035926379 # My solution
24.8638381019 # Accepted solution