[Tutor] n.isalnum() is failing

زياد بن عبدالعزيز البات زياد بن عبدالعزيز البات
Tue Jul 3 10:51:50 CEST 2007


Terry wrote:
> Hi!
> 
Hi...

  <snip>
> I am using x.isalnum() to check that I have a number for each year
> entered,  and it doesn't look to me like it is functioning properly.
  <snip>
That's because "x.isalnum()" will return True if "x" is not empty and 
it's content are *either* an Alpha or a Number (which is not what you want)!

You need to use "x.isdigit()" for your need.

Typing "help(str)" inside the Python shell will read:
  <snip>
  |  isalnum(...)
  |      S.isalnum() -> bool
  |
  |      Return True if all characters in S are alphanumeric
  |      and there is at least one character in S, False otherwise.
  |
  |  isalpha(...)
  |      S.isalpha() -> bool
  |
  |      Return True if all characters in S are alphabetic
  |      and there is at least one character in S, False otherwise.
  |
  |  isdigit(...)
  |      S.isdigit() -> bool
  |
  |      Return True if all characters in S are digits
  |      and there is at least one character in S, False otherwise.
  <snip>


Ziyad.


More information about the Tutor mailing list