以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. WWDC2014代码和视频下载

    WWDC2014 sample code 地址 http://pan.baidu.com/s/1qWGznnY WWDC2014 videos 地址 https://github.com/liubin ...

  2. jsp页面a标签URL转码问题

    简单的办法只有一句话,在后台对传过来的字符串(value)加一句: String value = new String(value.getBytes("ISO-8859-1"),& ...

  3. 前端开发学习笔记 - 1. Node.JS安装笔记

    Node.JS安装笔记 Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an ...

  4. (转)GitHub中PR(Pull request)操作 - 请求合并代码

    转:https://www.jianshu.com/p/b365c743ec8d 前言 本文尽量使用图形工具介绍如何向开源项目提交 Pull Request,一次亲身经历提交 PR 1.fork 项目 ...

  5. MySQL5.6transportable tablespace

    https://blog.csdn.net/xiaoyi23000/article/details/53150776

  6. SpringBoot系列:二、SpringBoot的配置文件

    SpringBoot的配置文件在resources文件夹下 springboot的配置文件支持两种形式的写法,一种是经典的properties另一种是yml yml通过空格缩进的形式来表示对象的层级关 ...

  7. DataFrame 结构

    概念 DataFrame 是表格型的数据结构 ,DataFrame 本质上可以看做是由series 组成的字典, 它既有行索引,也有列索引.  它并不是列表,也不是字典,.

  8. Java ——Number & Math 类 装箱 拆箱 代码块

    本节重点思维导图 当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double 等 int a = 5000; float b = 13.65f; byte c = 0 ...

  9. LeetCode 94. Binary Tree Inorder Traversal 动态演示

    非递归的中序遍历,要用到一个stack class Solution { public: vector<int> inorderTraversal(TreeNode* root) { ve ...

  10. 应用安全-CMF/CMS漏洞整理

    CMS识别 云悉 http://whatweb.bugscaner.com/batch.html CakePHP  CakePHP <= / Cache Corruption Exploit 2 ...