手机
当前位置:查字典教程网 >脚本专栏 >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学习资料

Python写的英文字符大小写转换代码示例

Python实现的百度站长自动URL提交小工具

Python基本数据类型详细介绍

Python开发编码规范

Python 变量类型及命名规则介绍

Python交换变量

python局域网ip扫描示例分享

精品推荐
分类导航