Python isalnum()方法

Python 字串 Python 字串


描述

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

語法

isalnum()方法語法:

str.isalnum()

參數

  • 無。

返回值

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

實例

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

實例(Python 2.0+)

#!/usr/bin/python # -*- coding: UTF-8 -*- str = "this2009"; # 字元中沒有空格 print str.isalnum(); str = "this is string example....wow!!!"; print str.isalnum();

以上實例輸出結果如下:

True
False

Python 字串 Python 字串