Latest web development tutorials

Python isalnum()方法

Python 字符串 Python字符串


描述

Python isalnum() 方法檢測字符串是否由字母和數字組成。

語法

isalnum()方法語法:

str.isa1num()

參數

  • 無。

返回值

如果string 至少有一個字符並且所有字符都是字母或數字則返回True,否則返回False

實例

以下實例展示了isalnum()方法的實例:

#!/usr/bin/python

str = "this2009";  # No space in this string
print str.isalnum();

str = "this is string example....wow!!!";
print str.isalnum();

以上實例輸出結果如下:

True
False

Python 字符串 Python字符串