Q:

How can I get a value that's inside parentheses in a string in Python?

I've got something like this:
a = '2(3.4)'
b = '12(3.5)'

I only want the value inside the brackets. I used regex, and it worked, but my teacher won't allow it. How can I do this?

A:

>>> a = '2(3.4)'
>>> a[a.index("(") + 1:a.rindex(")")]
'3.4'

A:

>>> a, b = '2(3.4)', '12(3.5)'
>>> def extract(string, start='(', stop=')'):
        return string[string.index(start)+1:string.index(stop)]

>>> extract(a), extract(b)
('3.4', '3.5')
>>> 

