如何在Python中的字符串中获取括号内的值?

mat*_*iit 5 python

我有这样的事情:

a = '2(3.4)'
b = '12(3.5)'
Run Code Online (Sandbox Code Playgroud)

我只想要括号内的值.我使用正则表达式,但它有效,但我的老师不会允许它.我怎样才能做到这一点?

Sve*_*ach 18

>>> a = '2(3.4)'
>>> a[a.index("(") + 1:a.rindex(")")]
'3.4'
Run Code Online (Sandbox Code Playgroud)