Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get number of string python

import re

example_str = "Here is a example number: 1234. Here is another: 5678"
number = re.findall("d+", example_str) # Get list of numbers in string
# d+ -> matches 1 or more (+) digits appearances in string
Comment

how to get a number from a string in python

string = "I am 14 years old"
for i in string.split():
  if i.isdigit():
    print(i)
print()
Comment

get number in string python

from itertools import groupby
my_str = "hello 12 hi 89"

l = [int(''.join(i)) for is_digit, i in groupby(my_str, str.isdigit) if is_digit]
Comment

PREVIOUS NEXT
Code Example
Python :: python read input 
Python :: how to find a prime number 
Python :: join lists python 
Python :: properties of tuples in python 
Python :: bar plot python 
Python :: np.arrange 
Python :: python print every n loops 
Python :: plotly coordinates mapping 
Python :: zip a directory in python 
Python :: how to join tables in python 
Python :: Username Promt using Python with Character Limit 
Python :: variables and data types in python 
Python :: plt delete space before axis 
Python :: unsplash python 
Python :: return mean of df as dataframe 
Python :: check if all elements in list are equal 
Python :: liste compréhension python 
Python :: axios django post 
Python :: handwritten digits data set 
Python :: pca 
Python :: python variable scope 
Python :: how to remove role discord bot python 
Python :: Customizable TKinter Buttons Python 
Python :: find highest value in array python 
Python :: python tuple and dictionary 
Python :: python string iterate 3 characters at a time 
Python :: django authenticate with email 
Python :: python update header row 
Python :: python3.8 
Python :: method get first last name python 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =