个人博客,支持一下呗!https://raycoder.me
本文首发于Ray’s Blog
什么是assert
?它的中文名叫做断言
。我们先来看一个简单的例子:
age = int(input())
if age>=18:
print('You can watch it!')
else:
print('You are too young!')
这个例子进行了一下18G操作,没有达到18岁的人会被拒之门外友善的提示。
不过,我们可以通过assert
关键字来实现同等的操作。
>>> age = int(input()