001_020 Python 使用Unicode来处理国际化文本

来源:互联网 发布:手机上写代码的软件php 编辑:程序博客网 时间:2024/05/21 23:00

代码如下:

#encoding=utf-8print '中国'#使用Unicode来处理国际化文本 #方案  编码转换ANSI为Unicode后处理print 'abc 中国'print unicode('abc 中国')print type('abc')print type( unicode('abc 中国'))print type( 'abc'+ unicode('abc 中国')) #Python 默认转化方式 :ANSI + UNICODE = UNICODE#建议 读入写入外部文件(File web and so on)时候确定好编码 ,即IO操作的时候

打印结果如下:

中国
abc 中国
abc 中国
<type 'str'>
<type 'unicode'>
<type 'unicode'>

0 0
原创粉丝点击