Python_18_Udacity_Evans_Intro to CS_2.5_How to solve problems

总目录


课程页面:https://www.udacity.com/course/intro-to-computer-science--cs101
授课教师:Dave Evans https://www.cs.virginia.edu/~evans/
如下内容包含课程笔记和自己的扩展折腾

assert

按照Udacity的思路,需要用assert
通过油管上这个五分多钟视频,快速了解了下assert怎么用。

# source: https://www.youtube.com/watch?v=BccybInHe8I
def power(x,y):
    # Assume that x and y are both non-neg numbers.
    assert x > 0, "x must be a positive number not %g" % x
    assert y > 0, "y must be a pos number not {0}".format(y)
    return x**y
print power(1, -3)

你可能感兴趣的:(Python_18_Udacity_Evans_Intro to CS_2.5_How to solve problems)