|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
原题:
将下面列表中的“小甲鱼”为“小鱿鱼“!
list1 = [1, [1, 2, ['小甲鱼']], 3, 5, 8, 13, 18]
我用的编辑器sublime text2,系统自带python 2.7
代码 :
#!/usr/bin/env python
# coding:utf8
import sys
reload(sys)
sys.setdefaultencoding("utf8")
list1 = [1, [1, 2, ['小甲鱼']], 3, 5, 8, 13, 18]
list1[1][2][0]='小鱿鱼'.encode('utf-8')
print list1
输出结果:
[1, [1, 2, ['\xe5\xb0\x8f\xe9\xb1\xbf\xe9\xb1\xbc']], 3, 5, 8, 13, 18]
[Finished in 0.0s]
# -*- coding:utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
list1 = [1, [1, 2, ['小甲鱼']], 3, 5, 8, 13, 18]
list1[1][2][0]='小鱿鱼'
print 'list1 list:%s' % str(list1).decode('string_escape')
#当然,用Python3以上版本不存在这个问题
|
|