Python 笔记

【2017.04.20】

List Comprehension

Notes of Python Tutorial:

A list comprehension consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses. The result will be a new list resulting from evaluating the expression in the context of the for and if clauses which follow it. For example, this listcomp combines the elements of two lists if they are not equal:

>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]

and it’s equivalent to:

>>> combs = []
>>> for x in [1,2,3]:
...     for y in [3,1,4]:
...         if x != y:
...             combs.append((x, y))
...
>>> combs
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]

Python 对象

is(), id(), isinstance()
type, class的统一;
is None 的真实含义

Slicing

两个索引参数构成先闭后开区间:

a = '12345'
>>> a[0:2]
'12'

Slice indices have useful defaults; an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced.

>>> a[:2]
'12'
>>> a[1:]
'2345'
>>> a[:]
'12345'

slicing还支持第三个参数 'step' 表示步进:

>>> a[::1]
'12345'
>>> a[::2]
'135'
>>> a[::3]
'14'
>>> a[::4]
'15'
>>> a[::-1] 用这个方法可以实现list反转
'54321'
>>> a[::-2]
'531'

【2017.05.02】

Division

Python 3.x 之后

  • real division: /
  • floor division: //

TODO 字符编码/Unicode的知识一直没有搞清楚

三目运算

X if C else Y

Parameter Group

func(*tuple_grp_nonkw_args, **dict_grp_kw_args)

异常体系

  • BaseException:
    • Exception
    • KeyboardException
    • SystemExit

【2017.05.03】

装饰器(Decorator)

本质上decorator就是一个函数;与被装饰函数组成复合函数;

Python Language Refference & PEP

一些更深入的、与语言设计相关的内容

reduce

reduce(func, [1, 2, 3]) === reduce(func(1, 2), 3)

Generator

yield 与 coroutine的关系??

import

examples suggest
import sys good
import sys, os, json bad
from module import name1[,name2] OK
from module import name1 good
from Tkinter import * bad
from cgi import FieldStorage as form good

Mutiple Inheritance

【20170517】
需要找另一个本书看下,
core p p 这本书整体讲的太啰嗦。
learning python 讲的可能好一点。

Classes and OOP

TODO 阅读 <Learning Python>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Python简介 Python历史 Python 是由 Guido van Rossum 在八十年代末和九十年代初...
    莫名其妙的一生阅读 1,150评论 0 2
  • 情绪管理,是我继时间管理之后关注较多的。 我是一个很情绪化的人,情绪爆发更是家常便饭。你们有多少人和我一样,特别是...
    温以沫阅读 453评论 0 4
  • 朱老师逼单过程回放 Q:只要便宜,我就用。 A:我们的开发成本在哪,不能优惠。 Q:华旺的才四千多,你要是也给我四...
    奔跑少年JC阅读 265评论 0 0
  • 互联网时代,人与人之间再也没有距离之说,一封电子邮件,就可以让彼此不熟悉的了互相了解;一个视频,可以让远在千里的亲...
    沈姐说说阅读 495评论 2 9
  • 今天在王妃小妞的群里看到在聊微整形就凑热闹多聊了几句。那个女孩子看到我也感兴趣就让我把自己素颜照片发给她。她看完后...
    Yuyu52的自留地阅读 535评论 0 1

友情链接更多精彩内容