

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Extract decimal numbers from a string in Python
Using RegEx module is the fastest way.
>>> import re
Assuming that the string contains integer and floating point numbers as well as below −
>>> s='my age is 25. I have 55.50 percent marks and 9764135408 is my number'
the findall() function returns a list of numbers matching given pattern which includes digit before and after decimal point
>>> re.findall('\d*\.?\d+',s)
Result is a list object of all numbers
['25', '55.50', '9764135408']
- Related Questions & Answers
- How to extract numbers from a string in Python?
- How to extract numbers from a string using Python?
- How to extract numbers from a string using regular expressions?
- Python – Extract Percentages from String
- Extract numbers from list of strings in Python
- How to extract date from a string in Python?
- Python – Extract Rear K digits from Numbers
- Extract only characters from given string in Python
- How to extract a substring from inside a string in Python?
- Python Regex to extract maximum numeric value from a string
- Python – Extract String elements from Mixed Matrix
- How can we extract the numbers from an input string in Java?
- How to extract numbers from text using Python regular expression?
- How to extract data from a string with Python Regular Expressions?
- Python – How to Extract all the digits from a String
Advertisements