Python 3 教程教程
Python 字符串判断
Python 字符串判断
Python 字符串判断
Python3 实例以下代码演示了Python字符串的判断:
实例
# Filename : test.py
# author by : www.verydoc.net
# 测试实例一
print("测试实例一")
str = "verydoc.net"
print(str.isalnum()) # 判断所有字符都是数字或者字母
print(str.isalpha()) # 判断所有字符都是字母
print(str.isdigit()) # 判断所有字符都是数字
print(str.islower()) # 判断所有字符都是小写
print(str.isupper()) # 判断所有字符都是大写
print(str.istitle()) # 判断所有单词都是首字母大写,像标题
print(str.isspace()) # 判断所有字符都是空白字符、\t、\n、\r
print("------------------------")
# 测试实例二
print("测试实例二")
str = "verydoc"
print(str.isalnum())
print(str.isalpha())
print(str.isdigit())
print(str.islower())
print(str.isupper())
print(str.istitle())
print(str.isspace())
# author by : www.verydoc.net
# 测试实例一
print("测试实例一")
str = "verydoc.net"
print(str.isalnum()) # 判断所有字符都是数字或者字母
print(str.isalpha()) # 判断所有字符都是字母
print(str.isdigit()) # 判断所有字符都是数字
print(str.islower()) # 判断所有字符都是小写
print(str.isupper()) # 判断所有字符都是大写
print(str.istitle()) # 判断所有单词都是首字母大写,像标题
print(str.isspace()) # 判断所有字符都是空白字符、\t、\n、\r
print("------------------------")
# 测试实例二
print("测试实例二")
str = "verydoc"
print(str.isalnum())
print(str.isalpha())
print(str.isdigit())
print(str.islower())
print(str.isupper())
print(str.istitle())
print(str.isspace())
执行以上代码输出结果为:
测试实例一 False False False True False False False ------------------------ 测试实例二 True True False True False FalsePython3 实例
Python 字符串判断 |
---|
Python 3 教程
Python的3.0版本,常被称为Python 3000,或简称Py3k。相对于Python的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向下兼容。