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 -*-
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())输出:
True
False
⑥判断所有字母都为小写
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'HELLO, WORLD!'
print(a.islower())
b = 'hello, world!'
print(b.islower())输出:
False
True
⑦判断所有单词的首字母为大写
# -*- coding:utf-8 -*-
if __name__ == "__main__":
a = 'HELLO, WORLD!'
print(a.istitle())
b = 'hello, world!'
print(b.istitle())
c = 'Hello, World!'
print(c.istitle())输出:
False
False
True
以上这篇Python 字符串大小写转换的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持帮客之家。
相关内容
- python实现的多线程端口扫描功能示例,python端口扫描
- Python第三方库xlrd/xlwt的安装与读写Excel表格,xlrdxlwt
- python使用xlrd与xlwt对excel的读写和格式设定,xlrdxlwt
- Python中struct模块对字节流/二进制流的操作教程,pytho
- python学习之面向对象【入门初级篇】,python面向对象
- Python 常用 PEP8 编码规范详解,pythonpep8
- Python 数据结构之堆栈实例代码,python堆栈
- Python 数据结构之队列的实现,python队列
- Python 详解基本语法_函数_返回值,python基本语法
- Python实现二分查找与bisect模块详解,pythonbisect
评论关闭