-4

Say I have an arbitrary string like

"abc 123 def 456"

How would I take out the integers so that it can print "123456" without using regex?

Spectre
  • 138
  • 7

1 Answers1

0

for your specific question, you can just use .isdigit()

s = "abc 123 def 456"

for ch in s:
    if ch.isdigit():
        print(ch, end='')
print()
0TTT0
  • 1,288
  • 1
  • 13
  • 23
  • please do not encourage zero effort questions – Julien Nov 03 '17 at 03:04
  • How is it zero effort? I think the first time I posted this it may have seemed like a dumb question, so I editied it.I need to extract the integers out of any string that is given to me, not just the specific one. – Spectre Nov 03 '17 at 03:07
  • this will extract (print) integers from any given string – 0TTT0 Nov 03 '17 at 03:08
  • 2
    @Rionic I understand that very well and my "solution" was sarcastic, but you have shown no code, no search, no effort whatsoever to solve your problem. – Julien Nov 03 '17 at 03:09
  • This is just a part of my full question, but it's the part I can't figure out, so I decided to just leave out the rest of my code as it would be unecessary. I've been working on the question for quite a while now. – Spectre Nov 03 '17 at 03:13