python 字母、数字、大小写相关函数

# -*- coding: UTF-8 -*-
  
example = "Peace and love"

print(example.isupper())		# 所有字符都是大写,真返回True,假返回False
print(example.upper())          # 把所有字符中的小写字母转换成大写字母

print(example.islower())		# 所有字符都是小写,真返回True,假返回False
print(example.lower())          # 把所有字符中的大写字母转换成小写字母

print(example.capitalize())     # 把第一个字母转化为大写字母,其余小写
print(example.istitle())		# 所有单词首字母均为大写,真返回True,假返回False
print(example.title())          # 把每个单词的第一个字母转化为大写,其余小写

print(example.isalnum())		# 所有字符只有数字或字母,真返回True,假返回False
print(example.isalpha())		# 所有字符只有字母,真返回True,假返回False
print(example.isdigit())		# 所有字符只有数字,真返回True,假返回False
print(example.isspace())		# 所有字符都是空字符,真返回True,假返回False
发布了32 篇原创文章 · 获赞 53 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_39378221/article/details/104025053