Python String Checks
The following code demonstrates checks on Python strings:
Example
Filename : test.py
author by : www.runoob.com
Test example one
(
"Test example one"
)
str
=
"runoob.com"
(
str
.
isalnum
(
)
)
Check whether all characters are digits or letters
(
str
.
isalpha
(
)
)
Check whether all characters are letters
(
str
.
isdigit
(
)
)
Check whether all characters are digits
(
str
.
islower
(
)
)
Check whether all characters are lowercase
(
str
.
isupper
(
)
)
Check whether all characters are uppercase
(
str
.
istitle
(
)
)
Check whether every word starts with a capital letter, like a title
(
str
.
isspace
(
)
)
Check whether all characters are whitespace, \t, \n, \r
(
"------------------------"
)
Test example two
(
"Test example two"
)
str
=
"runoob"
(
str
.
isalnum
(
)
)
(
str
.
isalpha
(
)
)
(
str
.
isdigit
(
)
)
(
str
.
islower
(
)
)
(
str
.
isupper
(
)
)
(
str
.
istitle
(
)
)
(
str
.
isspace
(
)
)
The output of the code above is:
测试实例一
False
False
False
True
False
False
False
------------------------
测试实例二
True
True
False
True
False
False
Python3 Examples