python字符串大小写转换的简单实例

下面小编就为大家带来一篇python 字符串大小写转换的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

①所有字母都转换为大写

# -*- coding:utf-8 -*-

if __name__ == “__main__”: a = ‘hello, world!’ print(a.upper())输出:

hello, world!

②所有字母都转换为小写

# -*- coding:utf-8 -*-

if __name__ == “__main__”: a = ‘hello, world!’ print(a.lower())输出:

hello, world!

③首字母转换成大写, 其余转换成小写

# -*- coding:utf-8 -*-

if __name__ == “__main__”: a = ‘hello, world!’ print(a.capitalize())输出:

hello, world!

④所有单词的首字母转换成大写, 其余转换成小写

# -*- coding:utf-8 -*-

if __name__ == “__main__”: a = ‘hello, world!’ print(a.title())输出:

hello, world!

⑤判断所有字母都为大写

# -*- coding:utf-8 -*-

if __name__ == “__main__”: a = ‘hello, world!’ print(a.isupper()) b = ‘hello, world!’ print(b.isupper())输出:

truefalse

⑥判断所有字母都为小写

# -*- coding:utf-8 -*-

if __name__ == “__main__”: a = ‘hello, world!’ print(a.islower()) b = ‘hello, world!’ print(b.islower())输出:

falsetrue

⑦判断所有单词的首字母为大写

# -*- coding:utf-8 -*-

if __name__ == “__main__”: a = ‘hello, world!’ print(a.istitle()) b = ‘hello, world!’ print(b.istitle()) c = ‘hello, world!’ print(c.istitle())输出:

falsefalsetrue

以上这篇python 字符串大小写转换的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持php中文网。

更多python 字符串大小写转换的简单实例相关文章请关注php中文网!

Posted in 未分类

发表评论