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 :: how to merge dataframe with different keys 
Python :: np zeros in more dimensions 
Python :: how to remove all characters from a string in python 
Python :: np random array 
Python :: python rock paper scissor 
Python :: pandas groupby aggregate quantile 
Python :: remove duplicates without changing order python 
Python :: previous value list loop python 
Python :: jupyter notebook check memory usage 
Python :: tribonacci sequence python 
Python :: how to print an input backwards in python 
Python :: python pil bytes to image 
Python :: django populate choice field from database 
Python :: transparancy argument pyplot 
Python :: sorted python lambda 
Python :: python print exception 
Python :: python get html info 
Python :: python for loop with array 
Python :: email authentication python 
Python :: django delete session 
Python :: python count lines in string 
Python :: create np nan array 
Python :: python if else variable assignment 
Python :: python webdriver element not interactable 
Python :: python get all ips in a range 
Python :: if you assign the result a void function to a variable in python, you get: 
Python :: cvtcoloer opencv 
Python :: python truncate to integer 
Python :: django template datetime-local 
Python :: python async threading 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =