Feb-27-2021, 07:12 PM
Why is that '\d' in a regular expression finds digits but then if those digits are stored in a variable, print(type(variable)) returns <class 'str'>?
1 2 3 4 5 6 7 8 9 10 11 12 |
import re string = ''' 10.00 22.34 31.23 ''' test_re = re. compile (r '\d' ) test = test_re.findall(string) print (test) for i in test: print ( type (i)) |
Output:['1', '0', '0', '0', '2', '2', '3', '4', '3', '1', '2', '3']
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>
<class 'str'>