Get all number from string by findall() in python by R4R Team


program-

#import the re module
import re

#take input of string
print("Enter string")
s=input()

#fill all numbers from the string
x=re.findall('d',s)
print("Number that are present in string :",x)


output-

Enter string
string1234 is a perfect 345 string
Number that are present in string : ['1', '2', '3', '4', '3', '4', '5']

Enter string
In this string,number is not present
Number that are present in string : []

Enter string
123456789
Number that are present in string : ['1', '2', '3', '4', '5', '6', '7', '8', '9']


-In this program, we take a input of string and find all numeric character in the string by using re.findall() function where 'd' is the meta sequence which are inform about the number.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!