Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> age = 10
>>> assert 0 < age < 100
>>> age = -1
>>> assert 0 < age < 100
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
assert 0 < age < 100
AssertionError
>>>
>>> age = 10
>>> assert 0 < age < 100 , "年龄输入错误!!!"
>>>
>>> age = -10
>>> assert 0 < age < 100 , "年龄输入错误!!!"
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
assert 0 < age < 100 , "年龄输入错误!!!"
AssertionError: 年龄输入错误!!!
>>> age = 210
>>> assert 0 < age < 100 , "年龄输入错误!!!"
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
assert 0 < age < 100 , "年龄输入错误!!!"
AssertionError: 年龄输入错误!!!
>>>
>>>
>>>
>>>
Python中的assert语句的使用
最新推荐文章于 2024-07-19 16:48:59 发布