【学习笔记】字符串和编码
来源:互联网 发布:北京索顿网络是培训吗 编辑:程序博客网 时间:2024/06/07 13:03
UTF-8
说实话之前我一直不知道历史
- UTF-8编码把一个Unicode字符根据不同的数字大小编码成1-6个字节,常用的英文字母被编码成1个字节,汉字通常是3个字节,只有很生僻的字符才会被编码成4-6个字节
注释写中文
Python的注释不能写中文让我很头大
D:\PythonProject>python helloworld.py File "helloworld.py", line 1SyntaxError: Non-UTF-8 code starting with '\xd6' in file helloworld.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
原来可以这样解决
#!/usr/bin/env python3# -*- coding: utf-8 -*-# 中文print('hello world')
- 第一行注释是为了告诉Linux/OS X系统,这是一个Python可执行程序,Windows系统会忽略这个注释;
- 第二行注释是为了告诉Python解释器,按照UTF-8编码读取源代码,否则,你在源代码中写的中文输出可能会有乱码。
占位符
一般来说%d和%s最常用
例如
#!/usr/bin/env python3# -*- coding: utf-8 -*-# 占位符的运用print('5 + 3 = %d is %s'%(5+3, "right"))
运行结果
D:\PythonProject>python helloworld.py5 + 3 = 8 is right
阅读全文
0 0
- 【学习笔记】字符串和编码
- python学习笔记-字符串和编码
- Python学习笔记 - 字符串和编码
- Python学习笔记—字符串和编码
- 【Python学习笔记】字符串和编码
- Python3学习笔记-字符串和编码
- Python学习笔记,5,字符串和编码问题
- 【Python】学习笔记——-2.2、字符串和编码
- Python学习 字符串和编码
- 【学习笔记】JavaScript编码规范-字符串
- python学习——字符串和编码
- python学习(5)字符串和编码
- 【学习笔记】BOM和UTF编码纪要
- 字符集和字符编码学习笔记
- iOS学习笔记——字符串编码转…
- iOS学习笔记——字符串编码转换
- python学习笔记(4):字符串及编码问题
- 【python3自学笔记3】—字符串和编码
- C++学习笔记--函数模板
- 实用网址链接
- apt-get update失败处理
- can not create a session after response is commited
- 搞科研(时序信号)
- 【学习笔记】字符串和编码
- Java递归实现输入任意目录,列出文件以及文件夹
- 542. 01 Matrix
- 机器学习作业9
- Java 的 多态
- ResourceExhaustedError: OOM when allocating tensor with shape[10,256,400,528]
- LeetCode-020 Valid Parentheses
- python logging日志模块的应用
- 杭电ACM OJ 1042 N! java大数乘法BigInteger