>> age = 10>>> assert 0 < age < 100>>> age = -1&_python assert 0">
当前位置:   article > 正文

Python中的assert语句的使用_python assert 0

python assert 0
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: 年龄输入错误!!!
>>> 
>>> 
>>> 
>>> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/559895
推荐阅读
相关标签
  

闽ICP备14008679号