Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python String Checks

Python String Checks

Document Object Reference Manual Python3 Examples

The following code demonstrates checks on Python strings:

Example

Filename : test.py

author by : www.runoob.com

Test example one

print

(

"Test example one"

)

str

=

"runoob.com"

print

(

str

.

isalnum

(

)

)

Check whether all characters are digits or letters

print

(

str

.

isalpha

(

)

)

Check whether all characters are letters

print

(

str

.

isdigit

(

)

)

Check whether all characters are digits

print

(

str

.

islower

(

)

)

Check whether all characters are lowercase

print

(

str

.

isupper

(

)

)

Check whether all characters are uppercase

print

(

str

.

istitle

(

)

)

Check whether every word starts with a capital letter, like a title

print

(

str

.

isspace

(

)

)

Check whether all characters are whitespace, \t, \n, \r

print

(

"------------------------"

)

Test example two

print

(

"Test example two"

)

str

=

"runoob"

print

(

str

.

isalnum

(

)

)

print

(

str

.

isalpha

(

)

)

print

(

str

.

isdigit

(

)

)

print

(

str

.

islower

(

)

)

print

(

str

.

isupper

(

)

)

print

(

str

.

istitle

(

)

)

print

(

str

.

isspace

(

)

)

The output of the code above is:


测试实例一
False
False
False
True
False
False
False
------------------------
测试实例二
True
True
False
True
False
False

Document Object Reference Manual Python3 Examples