python中assert_在Python中带有示例的assert关键字

python中assert

Python断言关键字 (Python assert keyword)

assert is a keyword (case-sensitive) in python, it is used to debug the code. Generally, it can be used to test a condition – if a condition returns False – it returns an Assertion Error (AssertionError).

assert是python中的一个关键字(区分大小写),用于调试代码。 通常,它可以用于测试条件-如果条件返回False-则返回断言错误(AssertionError)

Syntax of assert keyword

assert关键字的语法

    assert statement

Example:

例:

    Input:
num = 10
# assert statement
assert num==20
Output:
assert num==20
AssertionError

断言关键字的Python示例 (Python examples of assert keyword)

Example 1: Test a False result

示例1:测试错误的结果

# python code to demonstrate example of 
# assert statement 
num = 10    # number
# assert statements
# nothing will happed as the condition is true
assert num==10
#AssertionError will generate as the condition is false
assert num==20

Output

输出量

Traceback (most recent call last):
File "/home/main.py", line 12, in <module>
assert num==20
AssertionError

Example 2: Test a False result and return a customize message

示例2:测试错误结果并返回自定义消息

# python code to demonstrate example of 
# assert statement 
num = 10    # number
# assert statements
# nothing will happed as the condition is true
assert num==10
#AssertionError will generate as the condition is false
assert num==20, "There is an error with num's value"

Output

输出量

Traceback (most recent call last):
File "/home/main.py", line 12, in <module>
assert num==20, "There is an error with num's value"
AssertionError: There is an error with num's value

翻译自: https://www.includehelp.com/python/assert-keyword-with-example.aspx

python中assert

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/546262.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

单域MPLS ***数据转发实验分析

MPLS 数据详细转发流程示意图&#xff1a;配置思路&#xff1a;在自治系统AS100中配置IGP&#xff0c;使得两台PE路由器的lo 0接口路由可达&#xff1b;两台PE路由器路由可达后&#xff0c;在两台PE路由器之间建立MP-iBGP邻居关系&#xff0c;用来传输V4路由&#xff1b;AS100中…

python中list函数_list()函数以及Python中的示例

python中list函数Python list()函数 (Python list() function) list() function is a library function, it is used to create a list, it accepts multiple elements enclosed within brackets (because list() takes only one argument. Thus, the set of elements within b…

IDEA 终于支持中文版和 JDK 直接下载了(太方便了)附新版介绍视频

这是我的第 48 篇原创文章。IDEA 2020.1 经过了漫长的打磨终于发布正式版了&#xff0c;而这次的版本不止直接支持 Java 14&#xff0c;还带来了两个重量级的功能&#xff1a;官方中文版支持和 JDK 直接下载。在之前的开发中&#xff0c;当我们需要下载 JDK 时&#xff0c;通常…

【BO】WEBI文件打开时提示Illegal access错误

在infoview中打开WEBI文件时&#xff0c;提示如下错误。 通过查看SCN&#xff0c;找到错误原因是CMC中有一个服务没有启动。 启动这个服务即可&#xff1a; WebIntelligenceProcessingServer转载于:https://www.cnblogs.com/uzipi/p/3905513.html

华为交换机链路聚合使用ENSP模拟器进行实验

一、简介 链路聚合(Eth-Trunk)是将多个物理接口捆绑为一个逻辑接口,实现增加链路带宽,提高可靠性,提供负载分担的目的。 二、华为ENSP模拟器仿真图 华为交换机LSW1和LSW2端口G0/0/2、G0/0/3实现链路聚合,这2个交换机通过静态路由实现2个不同网段V10、V20互通。 三、华…

为什么工作很卖力,最后还晋升不了?

作者 | 军哥来源 | 军哥手记&#xff08;公众号ID&#xff1a;zxhy_cj&#xff09;最近写文章多了一些思考&#xff0c;要写对大家有价值的、有启发、有思考的东西&#xff0c;希望读者朋友们enjoy&#xff01;为什么自我感觉良好&#xff0c;可是晋升没我&#xff1f;感觉老板…

python 示例_Python中带有示例的class关键字

python 示例Python类关键字 (Python class keyword) class is a keyword (case-sensitive) in python, it is used to define a class, when we need to define a class, before the class name - we must have to use class keyword. class是python中的一个关键字(区分大小写)…

基于Java的数据采集(终结篇)

关于写过关于JAVA采集入库的三篇文章&#xff1a; 基于Java数据采集入库&#xff08;一&#xff09;&#xff1a;http://www.cnblogs.com/lichenwei/p/3904715.html 基于Java数据采集入库&#xff08;二&#xff09;&#xff1a;http://www.cnblogs.com/lichenwei/p/3905370.ht…

华为交换机、路由器配置单臂路由实现不同网段通信

一、eNSP模拟器仿真图 二、华为交换机配置 //批量创建VLAN [Huawei]vlan batch 10 20 //PC1电脑与交换机连接端口配置 [Huawei]interface GigabitEthernet0/0/2 [Huawei-GigabitEthernet0/0/2]port link-type access [Huawei-GigabitEthernet0/0/2]port default vlan 10 [Huaw…

python中的Lambda表达式/函数

Explanation: 说明&#xff1a; In python, there is a function named Lambda. Lambda function is an anonymous function - that means the function which does not have any name. 在python中&#xff0c;有一个名为Lambda的函数。 Lambda函数是一个匿名函数-表示该函数…

IDEA 正式版终于支持中文版和 JDK 直接下载了(太方便了)附介绍视频

IDEA 2020.1 经过了漫长的打磨终于发布正式版了&#xff0c;而这次的版本不止直接支持 Java 14&#xff0c;还带来了两个重量级的功能&#xff0c;官方中文版支持和 JDK 直接下载。 在之前的开发中&#xff0c;当我们需要下载 JDK 时&#xff0c;通常的步骤是这样的&#xff1…

HoughLine变换

对于HoughLine变换&#xff0c;有两种方法&#xff0c;标准霍夫变换&#xff08;SHT&#xff09;用的矩阵是CV_32FC2&#xff0c;用极坐标法记录直线,而累积概率霍夫变换&#xff08;PPHT&#xff09;用的是CV_32FC核心函数&#xff1a;cvCvtColor&#xff0c;cvHoughLines2&am…

华为交换机、路由器配置静态路由实现不同网段通信

一、eNSP模拟器仿真图 二、目标要求 在主核心交换机上配置vlanif10 192.168.10.254/24,vlanif20 192.168.20.254/24,vlanif100 192.168.100.1/24,PC1:192.168.10.1能ping通PC2:192.168.20.1,也能ping通PC3:192.168.30.1,交换机和路由器使用静态路由。 三、华为交换机配置…

答读者问:学历不高,要如何破局?

今天读者群在激烈讨论学历是否重要&#xff0c;有的朋友说非常重要&#xff0c;也有人说并没有那么重要。有读者问&#xff1a;“我是专科毕业&#xff0c;我需要读在职本科或者研究生吗”&#xff0c;也有读者问&#xff1a;“洋哥&#xff0c;三本毕业几年&#xff0c;想辞职…

python中三角函数_Python中的三角函数

python中三角函数Python三角函数/方法 (Python Trigonometric functions/methods) In python programming language, there are some of the built-in functions which are defined in math module – they can be used for Trigonometric calculations, python has following …

华为路由器配置OSPF实现不同网段通信

一、简介 PC1、PC2、LSW1和AR1配置单臂路由,实现PC1能够ping通PC2,具体实现请参考:华为交换机、路由器配置单臂路由实现不同网段通信。下面实现AR1和AR2通过配置OSPF,实现PC1能ping通PC3。 二、华为路由器配置 AR1新增配置: [Huawei]int g0/0/1 [Huawei-GigabitEthernet…

PHP开发框架[国内框架]

1.Thinkphp http://thinkphp.cn/ 2.Brophp http://www.brophp.com/zf/ 由LAMP兄弟连打造 3.WindFramework http://phpwind.github.com/windframework/framework.html 著名论坛程序phpwind推出的php框架 4.SpeedPHP http://www.speedphp.com/ 5.CanPHP http://www.canphp…

史上最全的 SQL 优化方案!建议收藏

在进行MySQL的优化之前&#xff0c;必须要了解的就是MySQL的查询过程&#xff0c;很多查询优化工作实际上就是遵循一些原则&#xff0c;让MySQL的优化器能够按照预想的合理方式运行已。图-MySQL查询过程1优化的哲学 注&#xff1a;优化有风险&#xff0c;涉足需谨慎a优化可能带…

python 示例_是Python中带有示例的关键字

python 示例Python是关键字 (Python is keyword) is is a keyword (case-sensitive) in python, it is used to check whether two objects are the same objects or not. is是python中的关键字(区分大小写)&#xff0c;用于检查两个对象是否相同。 Note: If two variables re…

Linux Podman安装MySQL数据库

1.拉取MySQL镜像 这里拉取官方最新版本镜像 podman pull mysql2.查看本地镜像 podman images可以看到&#xff0c;我们已安装最新版本的mysql镜像 3.运行容器 可以使用以下命令来运行 mysql 容器 podman run -d --name mysql-test -p 4000:3306 -e MYSQL_ROOT_PASSWORD12…