官方地址:https://docs.python.org/2.7/tutorial/index.html

本笔记只记录本人不熟悉的知识点

1 Whetting Your Appetite

2 Using the Python Interpreter

3 An Informal Introduction to Python

4 More Control Flow Tools、

5 Data Structures

6 Modules

7 Input and Output

Errors and Exceptions

9 Classes

 

 

3 An Informal Introduction to Python

(1)强制执行地板除//

(2)交互式模式下,_代表上一次打印的结果

(3)用r''来让反斜杠\不具有转义功能

(4)python中没有单独的字符类型,一个字符'a'其实表示长度为1的字符串

(5)python中,字符串是不可变的

(6)python中,当一个unicode字符串被打印、写入文件或者使用str()转化时,默认是将其编码为ascii码,当然ascii码只支持0~127个字符,碰到其他的字符会报错。

(7)使用切片是创建了一个新的list,里面的元素都是原list的拷贝。不过要注意,如果list包含的元素是对象,使用切片只会拷贝引用,其指向的对象则不会拷贝。

(8) python多变量赋值的顺序问题:a, b = b, a+b中,b 和 a + b会首先计算,然后同时赋值给a ,b。这种多变量赋值,都是首先计算完所有的右边,然后再同时赋值给左边。

(9) python可以在print 末尾加逗号如print a, 来避免print换行

 

4 More Control Flow Tools

(1)for循环遍历列表时如果需要往列表删除或插入元素,最好是先copy列表再遍历,使用切片语法可以很方便的copy列表。

(2)for ... else... : 当for循环遍历完列表时会执行else,如果是break出来,不会执行else。 while ... else ...同理,因为while条件不满足导致循环结束会执行else,如果是break出来则不会执行else。

(3)pass的一个用途:用于编程时待实现的函数。

def initlog(*args):
    pass   # Remember to implement this!
View Code

相关文章: