0

How to extract a number in the form of integer from a string

11th Jun 2020, 6:36 PM
Kartikeya Vasu
Kartikeya Vasu - avatar
5 Answers
+ 7
It's clear what you mean, but it would be a good idea if you could provide a sample string, that shows the input. Is it just one number or are there multiple occurrances or other numbers? Should they all be treated? Thanks!
11th Jun 2020, 8:07 PM
Lothar
Lothar - avatar
+ 6
txt = 'my age is 34' age = int(''.join([i for i in txt if i.isdigit()])) print(age)
12th Jun 2020, 10:00 AM
Lothar
Lothar - avatar
+ 1
Like for example str=input('my age is 34') So i want to have that 34 as an integer Thanks a lot
12th Jun 2020, 4:16 AM
Kartikeya Vasu
Kartikeya Vasu - avatar
+ 1
Thanks a lot bro Really helped
12th Jun 2020, 8:25 AM
Kartikeya Vasu
Kartikeya Vasu - avatar
0
no_dup = list(set([i for i in 'f1e10zp' if i.isdigit()])) dup = [i for i in 'f1e10zp' if i.isdigit()]
11th Jun 2020, 10:38 PM
Flash