diff --git a/Python/find_num.py b/Python/find_num.py new file mode 100644 index 0000000..d7b428c --- /dev/null +++ b/Python/find_num.py @@ -0,0 +1,20 @@ +# Find Numbers in a String : + +# Python3 code to demonstrate +# getting numbers from string +# using re.findall() +import re + +# initializing string +test_string = "There are 2 apples for 4 persons" + +# printing original string +print("The original string : " + test_string) + +# using re.findall() +# getting numbers from string +temp = re.findall(r'\d+', test_string) +res = list(map(int, temp)) + +# print result +print("The numbers list is : " + str(res))