Somethings about the coding in Python
来源:互联网 发布:java try的用法 编辑:程序博客网 时间:2024/05/16 12:04
In python3,the words will be coded in Unicode,so python3 support many languages.
- ord():output the int number of a charactor:
ord('a')ord('中')
- chr():output the charactor of a specific codeing number:
#the charactor 'B'chr(66)##the charactor '文'chr(25991)
- the type of str is coded with Unicode,the type of bytes is coded with ASCII,which means every charactor only costs 1 byte
- you can use encode() to change the coding:
#Unicode to ASCII'ABC'.encode('ascii')#Unicode to UTF-8'我爱你'.encode('utf-8')
- the data I received from network/disk is bytes(ASCII/UTF-8),So if I want to change it to Unicode,I can use decode function:
b'ABC'.decode('ascii')b'\xe4\xb8'.decode('utf-8')
- we will often meet the coding change between Unicode and bytes(UTF-8/ASCII).So usually we encouraged to use the UTF-8 all the time.So when the Python interpreter read the file,we need make it follow the UFT-8.You are supposed to add this two lines in the top of the file:
#!/usr/bin/python3# -*- coding:utf-8 -*-
The first line is the path of the python.It tells the Linux that this file is a python procedure .
The second line is to tell the python interpreter that this file should be read in UTF-8 in the memory.
阅读全文
0 0
- Somethings about the coding in Python
- Somethings about the Process in the Linux
- Somethings about the Process scheduler in Linux
- write somethings about my feelings
- Somethings About 《c++编程思想》
- About the logout in weblogic
- about the character string in C language
- About the Monitor object in .NET framework
- the solution about "messy code" in elicpse
- About Fast Lock in the WCE kernel
- the diary about awk scp in linux
- Some tips about Control Flow in Python
- Some tips about Class in Python
- About Module and Package in Python
- how to call c++ function in python coding in linux?
- Talking about the DDoS attack in the Internet
- Coding in the Shade: Using Eclipse with Google Data APIs
- Installing the google coding style settings in Eclipse
- Python学习_我该怎么使用字典
- 浅谈Spring注解
- LeetCode.55 Jump Game
- 机器学习入门--MNIST(一)
- IBM服务器引导盘serverguide 下载
- Somethings about the coding in Python
- UBoot:ENTRY等宏的展开,CPSR寄存器的设置(stat.S)
- sql排序问题
- Android音频子系统,音频流的回放(四)
- 【Java】【线程同步】sleep,join,yield,synchronized,wait,notify
- HDU 1029
- elasticsearch开发学习
- 【c#系列 三】从java到.net 高级
- js 去除空格、回车、换行