python 2.7小写

编程入门 行业动态 更新时间:2024-10-15 06:17:23
本文介绍了python 2.7小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我在 Python 2.7 中使用 .lower() 时,字符串不会转换为字母 ŠČŽ 的小写.我从字典中读取数据.

When I use .lower() in Python 2.7, string is not converted to lowercase for letters ŠČŽ. I read data from dictionary.

我尝试使用 str(tt["code"]).lower(), tt["code"].lower().

有什么建议吗?

推荐答案

使用 unicode 字符串:

Use unicode strings:

drostie@signy:~$ python Python 2.7.2+ (default, Oct 4 2011, 20:06:09) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print "ŠČŽ" ŠČŽ >>> print "ŠČŽ".lower() ŠČŽ >>> print u"ŠČŽ".lower() ščž

看到那个小u了吗?这意味着它是作为 unicode 对象而不是 str 对象创建的.

See that little u? That means that it's created as a unicode object rather than a str object.

更多推荐

python 2.7小写

本文发布于:2023-06-11 14:51:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/637061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!