How to extract only numbers from a string in Python

1 Answer

0 votes
def extract_numbers(s):  
 
    length = len(s) 
   
    chars = ""
    for i in range(0, length):  
        ch = s[i]  
        if ch.isdigit():  
            chars = chars + ch  
           
    return chars
       
      
s = "c++14$vb.net&%java*() php <>/python 3.7.3"
       
print(extract_numbers(s))  
 
 
'''
run:
 
14373
 
'''

 



answered Aug 14, 2019 by avibootz
...