Source: http://www.liaoxuefeng.com/

❤ Escape character: '\'

- '\n': newline;

- '\t': tab;

- '\\': \;

- r'...': no transferring for contents within single quotes;

- '''...''': multiple lines within triple quotes: could start a new line with ENTER directly. r'''...''' is valid as well.

❤ Division

- '/': floating point calculation, alway return float;

- '//': only return integer part (decimal part is direclty abandoned);

- '%': return remainder.

❤ Character encoding

- Encoding standard

.. ASCII: some symbold, number, uppercase and lowercase, 1 byte representing 1 character;

.. GB2312: Chinese character;

.. Unicode: encoding characters in all languages using one criterion, 2 bytes representing 1 character usually;

.. UTF-8: to save space, converting Unicode into 1-6 bytes (usually, one English character: 1 bytes, while one Chinses: 3 bytes); criterion used in RAM;

- Python

.. encoding using unicode;

.. for sigle character, ord() - obtaining integral representing for the character; chr() - converting code into character;

.. b'...': converting string to byte format (one byte fot each character);

.. '...'.encode('method'): encode ... using corresponding method('ascii', 'utf-8', note that Chinese characters cannot be encoded using 'ascii');

.. b'...'.decode('method'): decode byte string '...' into characters using corredponding method ('ascii', 'utf-8');

.. len('...'): obtain number of characters or bytes in '...';

.. formatting characters: the same way as c (and matlab :p):

%s - character string;

%d: integer;

%f: floating;

%x: hexadecimal integer.

some examples:


>>> 'Hello, %s' % 'world'
'Hello, world'
>>> 'Hi, %s, you have $%d.' % ('Michael', 1000000)
'Hi, Michael, you have $1000000'.
>>> '%2d-%02d' % (3, 1)
'3-01'
>>> '%.2f' % 3.1415
'3.14'
>>> 'Age: %s; Gender: %s' % (25, True)   # If you cannot decide which placeholder to use, just use %s
'Age: 25; Gender: true'
>>> 'Growth rate: %d %%' % 7
'Growth rate: 7 %'

NOTE: we should stick to 'utf-8' for converting to avoid chaos, to ensure which: 1. make sure your text editor is using: "UTF-8 without BOM" as encoding methods; 2. add the following two lines at the beginning of your script.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

Meet Python: little notes的更多相关文章

  1. Meet Python: little notes 3 - function

    Source: http://www.liaoxuefeng.com/ ♥ Function In python, name of a function could be assigned to a ...

  2. Meet Python: little notes 2

    From this blog I will turn to Markdown for original writing. Source: http://www.liaoxuefeng.com/ ♥ l ...

  3. Meet python: little notes 4 - high-level characteristics

    Source: http://www.liaoxuefeng.com/ ♥ Slice Obtaining elements within required range from list or tu ...

  4. python 100day notes(2)

    python 100day notes(2) str str2 = 'abc123456' print(str1.endswith('!')) # True # 将字符串以指定的宽度居中并在两侧填充指 ...

  5. 70个注意的Python小Notes

    Python读书笔记:70个注意的小Notes 作者:白宁超 2018年7月9日10:58:18 摘要:在阅读python相关书籍中,对其进行简单的笔记纪要.旨在注意一些细节问题,在今后项目中灵活运用 ...

  6. [Python Study Notes]匿名函数

    Python 使用 lambda 来创建匿名函数. lambda这个名称来自于LISP,而LISP则是从lambda calculus(一种符号逻辑形式)取这个名称的.在Python中,lambda作 ...

  7. [Python Study Notes]字符串处理技巧(持续更新)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  8. [Python Study Notes]with的使用

    在 Python 2.5 中, with 关键字被加入.它将常用的 try ... except ... finally ... 模式很方便的被复用.看一个最经典的例子: with open('fil ...

  9. [Python Study Notes]实现对键盘控制与监控

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

随机推荐

  1. ReactiveCocoa学习总结

    最近一直断断续续学习关于ReactiveCocoa的知识内容,对于它的一些基础内容将通过本文进行一个总结,主要是一些入门知识 一:RACSignal一些运用 @interface RACSignalT ...

  2. 【读书笔记】iOS网络-应用间通信

    一,URL方案 URL方案有3个主要用途:根据设备上其他应用的存在与否调整逻辑,切换到其他应用以及响应打开你的应用的其他应用.你还可以通过URL方案从某个站点或是在基于Web的认证流程结束是打开应用. ...

  3. AFNetworking菊花转圈圈

    注意,此圈圈是在左上角,特别小,不注意是看不到的 加载这个东西,要先引入头文件: AFNetworkActivityIndicatorManager.h 然后只要一句代码就可以实现,默认情况下AFN的 ...

  4. OC NSSet

    OC NSSet 数组的特点: 有序的 Set的特点: 无序的,存储元素无重复(例:set中有两个元素'a' 输出时只输出一个a) NSSet初始化 NSSet * set = [[NSSet all ...

  5. Lojic X

    媒体 赫兹 电话  500HZ 网络数据 8000HZ CD  44100HZ  电脑 48000HZ DVD 96000HZ 最大值(蓝光) 192000HZ   横向———————— 清晰度   ...

  6. Sql Server之旅——第七站 为什么都说状态少的字段不能建索引

    我们在学sqlserver的时候,大多教科书和前辈们都说状态少的字段不要建索引,由此带来的开销还不如不建索引,但是这句话有多少人真的知道, 或者说有多少人真的对此有比较深刻的理解,而不是听别人道听途说 ...

  7. php 升级到 5.3+ 后出现的一些错误,如 ereg(); ereg_replace(); 函数报错

    在php5.3环境下运行,常常会出现 Deprecated: Function ereg() is deprecated in...和Deprecated: Function ereg_replace ...

  8. 深入理解JVM—JVM内存模型

    我们知道,计算机CPU和内存的交互是最频繁的,内存是我们的高速缓存区,用户磁盘和CPU的交互,而CPU运转速度越来越快,磁盘远远跟不上CPU的读写速度,才设计了内存,用户缓冲用户IO等待导致CPU的等 ...

  9. viso2010从mysql中导出ER图

    mysql connector 下载地址: http://dev.mysql.com/downloads/connector/odbc/5.1.html 首先机器要安装mysql-connector- ...

  10. MarkDown插入图片

    MarkDown插入图片的语法 ·编辑器:MacDown 比如博客园的Logo,URL是 http://static.cnblogs.com/images/logo_small.gif 在要插入图片的 ...