伯克利CS61A-Sum2019-Week1

CS61A被公认为伯克利的一门神课,主讲语言为python,学透彻编程能力会有质的飞跃(个人观点),课程中的所有lab,hw,pro都可以下载练习,课程体验很棒~博主19年寒假的时候学习了一部分,准备利用暑假时间整理+学习
课程网址:https://cs61a.org/

基本操作

课程用的sublime,轻量级没法直接运行,高亮体验很棒~
写好后进入命令行交互运行 python3 -i lab01.py
运行doctest python3 -m doctest lab01.py

容易忽视的一些知识点
Division
True Division: /(decimal division)Floor Division // (integer division)
1 / 5 0.21 // 5 0
25 / 4 6.2525 // 4 6
4 / 2 2.0不是24 // 2 2
return and print
def what_prints():
    print('Hello World!')
    return 'Exiting this function.'
    print('61A is awesome!')

>>> what_prints()
Hello World!
'Exiting this function.'

print 打印出的字符串没有引号,return 返回的字符串有引号

Boolean Operators
  • not has the higest priority
  • and
  • or has the lowest priority

>>> True and not False or not True and False
>>> (True and (not False)) or ((not True) and False)

python的False:Falae [] {} () 0 None etc.
boolean operators 返回值

不必一定返回False,True,可以返回其他值

  • and stops evaluating any more expressions (short-circuits) once it reaches the
    first false value and returns it. If all values evaluate to a true value, the last
    value is returned.
  • or short-circuits at the first true value and returns it. If all values evaluate to
    a false value, the last value is returned.
>>> True and 1 / 0 and False
Error (ZeroDivisionError)

>>> True or 1 / 0 or False
True

>>> True and 0
0

>>> False or 1
1

>>> 1 and 3 and 6 and 10 and 15
15

>>> 0 or False or 2 or 1 / 0
2
Call expressions

在这里插入图片描述
To evaluate a function call:

  1. Evaluate the operator, and then the operands (from left to right).
  2. Apply the operator to the operands (the values of the operands).

If an operand is a nested call expression, then these two steps are applied to that inner operand first in order to evaluate the outer operand.

通俗来讲就是先进行括号里的操作,然后apply opperator to opperands,举个例子

print(print(1),print(2))
1
2
None None

补充知识:print函数的返回值为None
先执行print(1) 打印1,换行,然后执行print(2),打印2,然后相当于print(None,None)

Environments Diagrams

变量赋值:变量名 + 值
在这里插入图片描述
定义函数:函数名 + 箭头指向函数对象
在这里插入图片描述
调用函数

  1. Evaluate the operator, which should evaluate to a function.
  2. Evaluate the operands from left to right.
  3. Draw a new frame, labelling it with the following: 2
    • A unique index (f1, f2, f3, …)
    • The intrinsic name of the function, which is the name of the function object itself. For example, if the function object is func square(x)
    [parent=Global], the intrinsic name is square.
    • The parent frame ([parent=Global])
  4. Bind the formal parameters to the argument values obtained in step 2 (e.g.
    bind x to 3).
  5. Evaluate the body of the function in this new frame until a return value is
    obtained. Write down the return value in the frame.
python tutor 理解 Environment Diagrams

https://goo.gl/jM37t7
https://goo.gl/mjfnMn

第一篇博客,只是记录了一下所学内容,慢慢来~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值