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. iOS 单例模式 浅叙

    单例模式作用 可以保证在程序运行过程中,一个类只有一个实例,而且该实例易于供外界使用 从而方便地控制了实例个数,并节约系统资源 单例模式使用场合 在整个引用程序中,共享一份资源(这份资源只需要创建初始 ...

  2. Android启动模式launchMode

    在Android里,有4种Activity的启动模式并分别介绍下: standard singleTop singleTask singleInstance AndroidManifest.xml配置 ...

  3. xcode 删除文件后编译会出现*** is missing from working copy

    删除文件后  工程中会出现如图所示 如果你使用了svn管理工具  你就会看到如图所示 然后  选中  删除 就可以了 好了 多了 不多说了    最近比较忙   博客写的比较 少   等闲了  一定会 ...

  4. iOS-H5学习篇-01

    什么是HTML? HTML 是用来描述网页的一种语言. 0.HTML 指的是超文本标记语言 1.HTML 不是一种编程语言,而是一种标记语言 2.标记语言是一套标记标签 3.HTML 使用标记标签来描 ...

  5. NSDate 格式化 NSDate to NSString

    NSLog(@"%@",[NSDate stringFromDate:[NSDate date] withFormat:@"yyyyMMdd__HH_mm_ss_zzz& ...

  6. js:插入节点appendChild insertBefore使用方法

    首先 从定义来理解 这两个方法: appendChild() 方法:可向节点的子节点列表的末尾添加新的子节点.语法:appendChild(newchild) insertBefore() 方法:可在 ...

  7. 谈谈yii2-gii如何自定义模板

    作者:白狼 出处:http://www.manks.top/article/yii2_gii_custom_template本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位 ...

  8. Sqlite学习笔记(一)&&编译安装

    Sqlite简介 sqlite是一个开源的嵌入式文件数据库,sqlite以动态链接库的方式供应用程序调用,所有的数据库对象都存储在同一个文件中. sqlite动态库非常小,最新的3.8.11版本也只有 ...

  9. dubbox 编译 和 测试

    因为 dubbox 并没有发布到maven中央仓库仓库中,所以需要我们自己到官网下载,自己编译,install 到本地. 1. 首先安装git客户端工具 TortoiseGit, 然后使用它将 dub ...

  10. 一:c语言(数据类型和运算符)

    #include <stdio.h> /*就是一条预处理命令,它的作用是通知C语言编译系统在对C程序进行正式编译之前需做一些预处理工作.*/ int main() /*C程序就是执行主函数 ...