Python字符转换
时间:2021-08-23 04:47:13
如:
>>> print ord('a')
97
>>> print chr(97)
a
下面我们可以开始来设计我们的大小写转换的程序了:
#!/usr/bin/env python
#coding=utf-8
def UCaseChar(ch):
if ord(ch) in range(97, 122):
return chr(ord(ch) - 32)
return ch
def LCaseChar(ch):
if ord(ch) in range(65, 91):
return chr(ord(ch) + 32)
return ch
def UCase(str):
return ''.join(map(UCaseChar, str))
def LCase(str):
return ''.join(map(LCaseChar, str))
print LCase('ABC我abc')
print UCase('ABC我abc')
输出结果:
abc我abc
ABC我ABC
标签:Python,字符转换
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python Flask框架实现Proteus仿真Arduino与网页数据交互
2022-01-18 08:43:16
![](https://img.aspxhome.com/file/2023/0/89080_0s.png)
利用sys.sysprocesses检查SqlServer的阻塞和死锁
2011-11-03 17:24:11
Python中号称神仙的六个内置函数详解
2021-02-04 13:41:22
![](https://img.aspxhome.com/file/2023/3/70703_0s.jpg)
查看Oracle的执行计划一句话命令
2010-07-16 13:02:00
网站图片与文本谁更重要?(中英文对照)
2008-10-17 10:25:00
为网页设计创建有效的配色方案
2011-08-31 12:55:57
Python中ROC曲线绘制
2023-05-28 16:38:15
![](https://img.aspxhome.com/file/2023/8/97358_0s.jpg)
python中三种输出格式总结(%,format,f-string)
2022-06-11 16:34:40
![](https://img.aspxhome.com/file/2023/6/75356_0s.png)
Python super()函数使用及多重继承
2022-10-06 19:21:37
Python 解析简单的XML数据
2021-03-19 11:58:58
python中使用urllib2伪造HTTP报头的2个方法
2022-10-19 07:05:06
利用Python进行异常值分析实例代码
2022-06-30 16:14:59
![](https://img.aspxhome.com/file/2023/5/81835_0s.jpg)
使用ASP常见问题解答
2007-10-11 14:07:00
HTML5拿什么取代Flash?
2010-05-10 20:37:00
python reverse反转部分数组的实例
2021-09-16 05:30:11
python利用smtplib实现QQ邮箱发送邮件
2023-07-15 18:47:12
![](https://img.aspxhome.com/file/2023/6/98986_0s.jpg)
python3使用requests模块爬取页面内容的实战演练
2022-01-08 18:26:57
![](https://img.aspxhome.com/file/2023/5/90625_0s.png)
详解Django配置优化方法
2023-11-01 05:46:58
![](https://img.aspxhome.com/file/2023/6/86236_0s.png)
PyCharm配置anaconda环境的步骤详解
2023-07-26 10:11:20
![](https://img.aspxhome.com/file/2023/1/105561_0s.jpg)
什么是好的设计
2010-02-25 12:22:00