1import re
2s = "12 hello 52 19 some random 15 number"
3# Extract numbers and cast them to int
4list_of_nums = map(int, re.findall('\d+', s))
5print list_of_nums
1# This kind of conversion of types is known as type casting
2# Type of variable can be determined using this function type(variable)
3>>> string = '123'
4>>> type(string) # Getting type of variable string
5<class 'str'>
6>>> integer = int(string) # Converting str to int
7>>> type(integer)
8<class 'int'>
9>>> float_number = float(string) # Converting str to float.
10>>> type(float_number)
11<class 'float'>
12>>> print(string, integer, float_number)
13123 123 123.0