txt = '我是字符串'
txt_encode = txt.encode()
print(txt)
# 我是字符串
print(txt_encode)
# b'\xe6\x88\x91\xe6\x98\xaf\xe5\xad\x97\xe7\xac\xa6\xe4\xb8\xb2'
print(type(txt))
# <class 'str'>
print(type(txt_encode))
# <class 'bytes'>
txt_copy = txt_encode.decode( )
print(txt_copy)
# 我是字符串
print(type(txt_copy))
# <class 'str'> # str->bytes encode
# bytes->str decode

2020-05-07

encode 和 decode 的使用的更多相关文章

  1. [LeetCode] Encode and Decode Strings 加码解码字符串

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  2. 【python】python新手必碰到的问题---encode与decode,中文乱码[转]

    转自:http://blog.csdn.net/a921800467b/article/details/8579510 为什么会报错“UnicodeEncodeError:'ascii' codec ...

  3. LeetCode Encode and Decode Strings

    原题链接在这里:https://leetcode.com/problems/encode-and-decode-strings/ 题目: Design an algorithm to encode a ...

  4. Encode and Decode Strings

    Design an algorithm to encode a list of strings to a string. The encoded string is then sent over th ...

  5. encode和decode

    Python字符串的encode与decode研究心得乱码问题解决方法 为什么会报错“UnicodeEncodeError: 'ascii' codec can't encode characters ...

  6. 【python】浅谈encode和decode

    对于encode和decode,笔者也是根据自己的理解,有不对的地方还请多多指点. 编码的理解: 1.编码:utf-8,utf-16,gbk,gb2312,gb18030等,编码为了便于理解,可以把它 ...

  7. 271. Encode and Decode Strings

    题目: Design an algorithm to encode a list of strings to a string. The encoded string is then sent ove ...

  8. [LeetCode#271] Encode and Decode Strings

    Problem: Design an algorithm to encode a list of strings to a string. The encoded string is then sen ...

  9. Encode and Decode Strings 解答

    Question Design an algorithm to encode a list of strings to a string. The encoded string is then sen ...

  10. python encode和decode函数说明【转载】

    python encode和decode函数说明 字符串编码常用类型:utf-8,gb2312,cp936,gbk等. python中,我们使用decode()和encode()来进行解码和编码 在p ...

随机推荐

  1. 数据库管理与迁移(Liquibase)

    SpringBoot 是为了简化 Spring 应用的创建.运行.调试.部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖 ...

  2. js小案例(排他案例)

    描述:点击哪个,哪个就变蓝色,其余的都是粉色 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  3. win10 麦克风无法使用,可能是设置了权限

    驱动什么的都正常,平白无故麦克风不好用了,原来是之前自己设置了麦克风权限: 把这个开关打开就可以了. (完)

  4. Javascript 中 数组遍历 forin和forof 的区别

    定义一个数组 let array = [1, 2, 3, 4]; for (let a in array){ console.log("遍历a的值 "+a+"”,数组中的 ...

  5. Mac安装文件已勾选“允许任何来源”,还是提示“文件已损坏”的解决方案

    Mac安装文件已勾选"允许任何来源",还是提示"文件已损坏"的解决方案 打开终端,在终端中粘贴下面命令:[sudo xattr -r -d com.apple. ...

  6. 阿里云Linux CentOS8.1 用 xshell 上传和下载文件

    下载: 例如有一个script 文件夹,我们要把它打包成 tar文件,并下载到本地.具体命令如下: 1.进入script 所在的目录,先打包,命令如下: tar -cvf script.tar scr ...

  7. 【git】配置git命令行别名

    引言:由于有些git命令较长,记起来比较麻烦,为了git工具使用的方便,为命令行取别名有很大的必要. 1.在家目录添加.gitconfig文件. 此文件在创建git仓库时,一般是没有的,需要手动添加. ...

  8. 创建新用户后无法切换 su: failed to execute /bin/bash: Permission denied

    创建新用户后无法切换 su: failed to execute /bin/bash: Permission denied   当使用 su username 从root切换用户时显示 su: fai ...

  9. 将PDF转化为wrod

    public static void CreateWord(string HtmlPath, string WordSavePath) { string inputName = HtmlPath; / ...

  10. adb devices 不能连接设备 could not install *smartsocket* listener

    cmd以管理员身份运行命令adb devices  或adb reverse tcp:8081 tcp:8081,无法连接设备,出现上图信息. 输入命令:adb kill-server 再输入:adb ...