python3 assert 断言的使用详解 (区别于python2)

作者:妖白 时间:2023-03-10 03:05:26 

python3 和python以前的版本有点不同

如果你断言的 语句正确 则什么反应都没有

但是如果你出错之后 就会报出 AssertionError 并且错误可以自己填写

格式 : assert+空格+要判断语句+双引号“报错语句”

例子:

出错时候


assert 1>5, "chucuo"

输出值为:


---------------------------------------------------------------------------
AssertionError              Traceback (most recent call last)
<ipython-input-5-6aa3d3e733df> in <module>()
----> 1 assert 2>5, "chucuo"

AssertionError: chucuo

不出错时


        assert 1>5, "chucuo"

输出值 : 什么也不输出

来源:https://blog.csdn.net/qq_24753293/article/details/78066426

标签:python3,assert,断言,python2
0
投稿

猜你喜欢

  • Python中的 pass 占位语句

    2023-02-21 20:45:12
  • Python实现检测文件的MD5值来查找重复文件案例

    2021-08-14 01:28:02
  • Frontpage中网页字体的美化研究

    2008-03-10 12:13:00
  • python全栈要学什么 python全栈学习路线

    2023-07-03 17:55:19
  • 初识Firebug 全文 — firebug的使用

    2007-10-23 12:54:00
  • 详解Go中Map类型和Slice类型的传递

    2024-04-23 09:47:03
  • 在ASP中使用SQL语句之9:表单操作

    2007-08-11 13:18:00
  • sql 百万级数据库优化方案分享

    2024-01-20 13:20:24
  • python多进程共享变量

    2023-08-30 07:40:53
  • python中的__init__ 、__new__、__call__小结

    2021-07-19 20:10:38
  • iview实现动态表单和自定义验证时间段重叠

    2023-07-02 17:09:28
  • Python报错:对象不存在此属性的解决

    2023-05-30 20:12:56
  • Python %r和%s区别代码实例解析

    2023-10-07 17:01:08
  • Tensorflow之MNIST CNN实现并保存、加载模型

    2023-10-16 06:21:33
  • vue项目中Eslint校验代码报错的解决方案

    2024-05-10 14:09:18
  • 详解Python prometheus_client使用方式

    2022-01-17 11:09:37
  • Python函数式编程中itertools模块详解

    2022-08-28 20:16:53
  • 细化解析:MySQL 服务器究竟有多稳定?

    2009-01-14 11:55:00
  • 感觉很流畅的js实现的键盘控制(带惯性)

    2024-04-30 10:11:38
  • 基于Python数据可视化利器Matplotlib,绘图入门篇,Pyplot详解

    2022-11-20 07:59:16
  • asp之家 网络编程 m.aspxhome.com