以u或U开头的字符串表示unicode字符串

如果你想要用非英语写文本,那么你需要有一个支持Unicode的编辑器。(了解一下unicode和ascll码还有utf-8)

u'你好'        #这里是把‘你好’用Unicode编码

r'\nabdcd\rds'    #这里加上r表示 把\nabdcd\rds看做原始字符,忽略一切转意字符
 
 
 
unicodestring = u"Hello world"
# 将Unicode转化为普通Python字符串:"encode"
utf8string = unicodestring.encode("utf-8")
asciistring = unicodestring.encode("ascii")
isostring = unicodestring.encode("ISO-8859-1")
utf16string = unicodestring.encode("utf-16")
# 将普通Python字符串转化为Unicode:"decode"
plainstring1 = unicode(utf8string, "utf-8")
plainstring2 = unicode(asciistring, "ascii")
plainstring3 = unicode(isostring, "ISO-8859-1")
plainstring4 = unicode(utf16string, "utf-16")
assert plainstring1 == plainstring2 == plainstring3 == plainstring4

python字符串前面的u,还有r的更多相关文章

  1. python字符串前面的r/u/b的意义 (笔记)

    u/U:表示unicode字符串 : 不是仅仅是针对中文, 可以针对任何的字符串,代表是对字符串进行unicode编码. r/R:非转义的原始字符串: 与普通字符相比,其他相对特殊的字符,其中可能包含 ...

  2. [Python][小知识][NO.1] Python字符串前 加 u、r、b 的含义

    1.字符串前加 u 例:u"我是含有中文字符组成的字符串." 作用:后面字符串以 Unicode 格式 进行编码,一般用在中文字符串前面,防止因为源码储存格式问题,导致再次使用时出 ...

  3. [python]去掉 unicode 字符串前面的 u(转)

    add by zhj: 其实一般情况下,不会遇到变量c这种编码的,往往是哪些出错了,才会出现这种情况.所以遇到这种情况,要先 查看代码,避免这种情况的出现 原文:https://mozillazg.c ...

  4. jquery获取value值时将数字型字符串前面的0自动截取处理方法

    <li class="cwhite" value="02" id="02" onclick="getQuestionList ...

  5. 转 python 字符串前加r

    在打开文件的时候open(r'c:\....') 加r和不加''r是有区别的 'r'是防止字符转义的 如果路径中出现'\t'的话 不加r的话\t就会被转义 而加了'r'之后'\t'就能保留原有的样子 ...

  6. python字符串前带u,r,b的含义

    1. https://www.cnblogs.com/yanglang/p/7416889.html 2.https://blog.csdn.net/teavamc/article/details/7 ...

  7. JAVA去掉字符串前面的0

    最佳方案:使用正则 String str = "000000001234034120"; String newStr = str.replaceAll("^(0+)&qu ...

  8. js 去掉字符串前面的0

    <script>var a='00123';alert(a.replace(/\b(0+)/gi,""));</script>

  9. 初学Python——字符串相关操作

    基本字符串操作 Pyhton中字符串的格式化输出在前面已经总结了,接下来介绍一些常用的字符串操作 先定义一个字符变量,以下的操作都以此为例: name=" my name is china ...

随机推荐

  1. Oracle Flashback Database

    Oracle Flashback Database Ensure that the prerequisites described in Prerequisites of Flashback Data ...

  2. vue +ts 的一次踩坑日记

    在vue的方法里面写事件的时候比如写一个路由跳转,方法大概如下:  goBack1() {            console.log(this);            this.$router. ...

  3. 三十六、python 中subprocess介绍

    import subprocess 1.执行系统命令subprocess.call('ipconfig') #shell=False时,拼接命令分开写,放在列表中,等于True时,可写一块,空格隔开例 ...

  4. 【cs231n作业笔记】一:KNN分类器

    安装anaconda,下载assignment作业代码 作业代码数据集等2018版基于python3.6 下载提取码4put 本课程内容参考: cs231n官方笔记地址 贺完结!CS231n官方笔记授 ...

  5. dcef3 为按钮添加单击事件

    http://ju.outofmemory.cn/entry/78083 dcef3 为按钮添加单击事件 BccSafe's Blog 2014-06-01 3706 阅读 DOM 演示dcef3操作 ...

  6. pandas 基础介绍与概览

    pandas是 基于NumPy数组构建的,特别是基于数组的函数和不使用for循环的数据处理 相关联的几个库, 分析库 scikit-learn 和 statsmodels 数值计算工具,NumPy 可 ...

  7. Python解决NameError: name 'reload' is not defined的问题

    遇到这个问题,对于 Python 2.X: import sys reload(sys) sys.setdefaultencoding("utf-8") 对于 Python 3.3 ...

  8. Bootstrap 学习笔记 项目实战 响应式轮播图

    左右两个箭头可以随浏览器缩放进行移动 保持在图片中间 Html代码: <!DOCTYPE html> <html lang="zh-cn"> <hea ...

  9. 精灵图和base64如何选择

    Css Sprites: 介绍: Css Sprites(雪碧图或css精灵),是网页图片处理的一种方式,它允许你将一个页面涉及到的所有零星图片都包含到一张大图中去,这样一来,当访问该页面时,载入的图 ...

  10. STL 配接器(adapters)

    定义 配接器(adapters):将一个class的接口,转换为另一个class的接口,使得原来不能一起使用相互兼容的classes,可以一起协同工作. 配接器是一种设计模式. STL中提供的各种配接 ...