(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
c
haracters.
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.