位置: 编程技术 - 正文

Python 字符串大小写转换的简单实例(Python字符串大写)

编辑:rootadmin

推荐整理分享Python 字符串大小写转换的简单实例(Python字符串大写),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:python字符串大小比较规则,Python字符串大写,Python 字符串大写转小写,Python 字符串大小,Python 字符串大小写转换,python字符串大小写反转,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 -*-

Python 字符串大小写转换的简单实例(Python字符串大写)

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 字符串大小写转换的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持积木网。

python实现的多线程端口扫描功能示例 本文实例讲述了python实现的多线程端口扫描功能。分享给大家供大家参考,具体如下:下面的程序给出了对给定的ip主机进行多线程扫描的Python代码#!/usr

Python第三方库xlrd/xlwt的安装与读写Excel表格 前言相信大家都应该有所体会,在平时经常会遇到处理Excel表格数据的情况,人工处理起来实在是太麻烦了,我们可以使用Python来解决这个问题,我们需

python使用xlrd与xlwt对excel的读写和格式设定 前言python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库。本文主要介绍了python使用xlrd与xlwt对excel的读写和格式设定,下面话不多

本文链接地址:https://www.jiuchutong.com/biancheng/381338.html 转载请保留说明!

上一篇:linux平台使用Python制作BT种子并获取BT种子信息的方法(linux py)

下一篇:python实现的多线程端口扫描功能示例(python多线程菜鸟教程)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络