手机
当前位置:查字典教程网 >脚本专栏 >python >Python字符转换
Python字符转换
摘要:如:>>>printord('a')97>>>printchr(97)a下面我们可以开始来设计我们的大小写转换的程序了:复制代码代码如下:#...

如:

>>> 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字符转换】相关文章:

python抓取网页时字符集转换问题处理方案分享

Python学习资料

Python入门第1/10页

python局域网ip扫描示例分享

python转换字符串为摩尔斯电码的方法

python网络编程学习笔记(四):域名系统

Python判断字符串与大小写转换

python中将字典转换成其json字符串

Python基本数据类型详细介绍

Python字符遍历的艺术

精品推荐
分类导航