think python内容提纲

think python内容提纲
python 2.7 document
https://docs.python.org/2.7/library/index.html

chapter1
python is an interpreted language. it is executed by an interpreter. there are two ways to use the interpreter: interactive mode (similar to MATLAB command window) and script mode

chapter2

  1. types of values: int, float, str, bool, list (use […,…]), tuple (use (…,…)), dict (use {…:…,…:…})
  2. octal format: start with 0 such as 0108
    hexadecimal format: start with 0x such as 0x10
    16
  3. keywords:
    [‘and’, ‘as’, ‘assert’, ‘break’, ‘class’, ‘continue’, ‘def’, ‘del’, ‘elif’, ‘else’, ‘except’, ‘exec’, ‘finally’, ‘for’, ‘from’, ‘global’, ‘if’, ‘import’, ‘in’, ‘is’, ‘lambda’, ‘not’, ‘or’, ‘pass’, ‘print’, ‘raise’, ‘return’, ‘try’, ‘while’, ‘with’, ‘yield’]
    you can get keywords list by inputing the following commands:
    import keyword
    keyword.kwlist
    keyword.iskeyword(s) #Return true if s is a Python keyword.
  4. operators:
    + addition (‘ha’+‘lol’‘halol’)
    - subtraction
    * multiplication (‘ha’*3
    ’hahaha’)
    / floor division in python2 and division in python3 (floor division: 5/60; -1/6-1)
    ** exponentiation [ˌekspəʊˌnenʃɪ’eɪʃən] 求幂
    ^ XOR
  5. comments start with the # symbol

chapter3
swampy下载地址:
http://www.greenteapress.com/thinkpython/swampy/

  1. type conversion functions:
    int(‘32’)
    int(3.999)
    float(‘3.14’)
    float(32)
    str(32)
    str(3.14)
  2. math functions
    import math
    math.log10(100)==2.0
    math.log(math.e)==1.0
    math.sin(math.pi/6)==0.49999999999999994
    math.sqrt(2)==1.4142135623730951
    math.exp(math.log(3))==3.0000000000000004
    ……
  3. variables and parmeters are local
  4. function: fruitful functions (chapter6) and void functions
  5. function definition
    def function_name(parameter1,parameter2,……)
    function body
  6. importing with from
    (1) import math
    math.pi
    (2) from math import pi
    pi
    (3) from math import * (there might be conflicts between names defined in different modules)
    pi
    sin(pi/2)

chapter4 function interface design

  1. encapsulation 函数封装 (lines of commands -> function)
    generalization 函数泛化(square -> polygon, 从而circle可以调用polygon)
    refactoring: rearranging a program to improve function interfaces and facilitate code reuse

  2. for-looping
    >>> print range(4)
    [0, 1, 2, 3]
    >>> sum=0
    >>> for i in range(4):

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值