Python Forum
checking if there are numbers in the string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
checking if there are numbers in the string
#10
(Apr-05-2017, 10:56 PM)Sp00f Wrote: i tried x.digit(), and that worked as well.
The name is not important "rubberduck" is now temporarily assigning to each element in string flyTo.
>>> flyTo = 'yes9'
>>> any(rubberduck.isdigit() for rubberduck in flyTo)
True
When say "not important" so is c much better than rubberduck when iterate over characters.
To see each value can use list comprehension.
>>> flyTo = 'yes9'
>>> [rubberduck.isdigit() for rubberduck in flyTo]
[False, False, False, True]
Interactive shell can give info about a lot of stuff.
>>> help(any)
Help on built-in function any in module builtins:

any(...)
    any(iterable) -> bool
    
    Return True if bool(x) is True for any x in the iterable.
    If the iterable is empty, return False.

>>> flyTo = 'yes9'
>>> help(flyTo.isdigit)
Help on built-in function isdigit:

isdigit(...) method of builtins.str instance
    S.isdigit() -> bool
    
    Return True if all characters in S are digits
    and there is at least one character in S, False otherwise. 
Reply


Messages In This Thread
RE: checking if there are numbers in the string - by snippsat - Apr-06-2017, 12:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pulling Specifics Words/Numbers from String bigpapa 2 823 May-01-2023, 07:22 PM
Last Post: bigpapa
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,613 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  Checking if a string contains all or any elements of a list k1llcod3 1 1,183 Jan-29-2023, 04:34 AM
Last Post: deanhystad
  Find and Replace numbers in String giddyhead 2 1,291 Jul-17-2022, 06:22 PM
Last Post: giddyhead
  Finding line numbers starting with certain string Sutsro 3 2,607 Jun-27-2020, 12:36 PM
Last Post: Yoriz
  checking a string for two instances of .. Skaperen 2 1,626 May-13-2020, 09:58 PM
Last Post: Skaperen
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,808 May-09-2019, 12:19 PM
Last Post: Pleiades
  String format checking? MuntyScruntfundle 1 2,468 Mar-06-2019, 12:01 PM
Last Post: buran
  Extract numbers from string ian 1 2,845 Apr-28-2018, 10:40 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020