Reputation: 81
In my program I want to check if the stroke symbol is a common digit (0-9)
.isnumeral works strange because it counts alphabeticals (a-z) as True, well then I lurked in and got that .isnumeral isn't actually searching exclusively for what I want - digits. And through the manual I found .isdigit but:
dna = 'a3'
start = 0
end = 1
if dna[end].isdigit is True:
print('Yes')
It's not working and 'Yes' isn't showing as expected.
Upvotes: 0
Views: 632
Reputation: 185
Two things:
there's no need to compare to true, just use the result from isdigit()
isdigit() is a function, which is truthy on its own, but does not equate to True
Check out the Python docs for more info.
Upvotes: 1
Reputation: 566
dna[end].isdigit
in this case is referring to a str.isdigit
function.
If you do print(type(dna[end].isdigit))
you will see what I mean.
To call the function instead, add paranthesis like this if dna[end].isdigit():
Upvotes: 1
Reputation: 2614
You must actually call the isdigit()
method:
dna = 'a3'
start = 0
end = 1
if dna[end].isdigit():
print('Yes')
This gives your expected answer, True.
If you do dna[end].isdigit
it just gives an object <built-in method isdigit of str object at address>
which won't evaluate.
Upvotes: 1
Reputation: 33335
if dna[end].isdigit is True:
isdigit()
is a function, not an attribute.
You forgot the parentheses on the end, therefore you're referring to the function object itself, instead of the result of calling the function.
Upvotes: 4