python字符转换(ascii码转换)
来源:互联网 发布:阿里外包员工出路 知乎 编辑:程序博客网 时间:2024/05/25 16:38
如:
>>> 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
>>> 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字符转换(ascii码转换)
- 字符ASCII码转换
- 转换字符为ASCII码
- JS 字符/ASCII码转换
- python中实现字符与其ASCII码间的转换
- Python字符与ASCII码之间的转换
- python中ascii码和字符的转换
- python中ascii码和字符的转换
- python中ascii码和字符的转换
- python中ASCII和十六进制字符转换
- python-ASCII与字符间的转换
- 字符ascii码与字符的转换
- C#字符与数字互相转换,字母转换成ASCII码,ASCII码转换字符
- 中文字符转换为ascii码
- 字符及中文转换到Ascii码
- c#中字符与ASCII码转换
- ASCII码与字符相互转换
- ascii码与字符的相互转换
- AVPlayer vs. AVAudioPlayer
- ssh整合An AnnotationConfiguration instance is required to use <mapping class="“错误解决方法
- c++ 虚函数以及抽象类
-
- 运用BCP导出数据库大批量数据以及导入大批量数据到数据库
- python字符转换(ascii码转换)
- 《程序员》 -- 视觉与交互设计——从iOS 7谈起
- Sprite Kit的简单使用Demo
- go语言将函数作为参数传递
- dp-史上最戳最长最臭代码-hdu-4733-G(x)
- JavaMail发送HTML邮件 no object DCH for MIME type multipart/mixed;异常
- Unable to execute dex: Multiple dex files define 的解决方法
- linux下更改用户名
- 【转载】【leetcode】Median of Two Sorted Arrays