Python Assert Statement

This article will learn the concept in Python using confession.

Table of Contents

  • What is Assertion?
  • Python assert Statement
  • Key Points to Remember

What is Assertion?


Verification is statements that show the reality or state of your program's confidence. For example, when you write the part, make sure that the partition is zero, the unknown part is zero.
Confirmation is the charcoal story that makes it easy to check whether the situation is true or not. If it is true, the program has not done so and has been moved to the first line of code. However, if it is false, the program stops and the error has been made.
It is also a mistake tool because it helps stop the program from happening and the errors shown in the program that indicate errors.
You can learn more about the article in the article: The benefits of the program are confirmed
We can delete the following track record:
                                                      

Python Assert Statement:


Python has a built-in vocabulary that shows the use of the state's program declaration. To clarify the declaration or state of the state he thinks it is always true. If the situation is fake, the program is stopped and AssertionError is paid.
The word used in Python:

assert <condition>
assert <condition>,<error message>

In Python, we can use a clear statement of two ways as above.
1. The declaration states that the situation and, if not met, the program will stop and give AssertionError.
2. The text can also specify the status and error of the error message. If the situation is not covered, they say stopping the program and giving AssertionError and error message.
Let's take examples, where we have a calculator that calculates the average price and the user must be a blank list. We will use the instructions to look at the borders and make sure if the length of the lists is submitted is zero, the program stops.

Example 1: Use non-confidential message without error


def avg(marks):
    assert len(marks) != 0
    return sum(marks)/len(marks)
 mark1 = []
print("Average of mark1:",avg(mark1))

When we implement the old program, productivity will be:

AssertionError

I am wrong when you fill out the 'Mark1' list and inaccurate in the statement, the situation becomes a fraud and will implement the AssertionError program.
Now we will pass another list to satisfy the requirements and how we will be leaving.

Example 2: Use of error message verification


def avg(marks):
    assert len(marks) != 0,"List is empty."
    return sum(marks)/len(marks)

mark2 = [55,88,78,90,79]
print("Average of mark2:",avg(mark2))

mark1 = []
print("Average of mark1:",avg(mark1))

When we implement the old program, productivity will be:

Average of mark2: 78.0
AssertionError: List is empty.

We refer to an unmarked mark as well as a MarkG portal list () and we have a product mark2, but then, we have an AssertionError error: list. The conditions will be documented on this list of approved programs in the program. However, Mark1 is unwanted condition giving AssertionError.

Key points to Remember


• Guaranteeing Boolean expressions should always be in the law.
• Print the text using a message and a message.
• Evidence of identification is used to verify the value of the performance debate and output.

• Proof of evidence is used as an incorrect device because it stops the program error.

To getting expect level training for Python training in your Location – Python training in Chennai | Python training institute in Chennai | Python Course institute in Chennai | Python training in Bangalore | Python training institute in Bangalore Python training in Electronic City Python training in Jaya Nagar | Python training in Pune | Python training institute in Pune | Python training in OMR | Python training in Velachery | Python training in Tambaram Python training in Annanagar | Python training in Marathahalli Python training in Btm | Python Online Training | Online Certification Course Python Course in Chennai Python interview questions and answers | Python tutorials | Python training in Indira Nagar | Python Course in Btm | Python Course in Marathahalli Python training institute in Marathahalli Python course institute in Btm Python course in Electronic City | Python online training in Chennai | Python online training in Bangalore | Python Interview Questions & Answers

Comments

Post a Comment

Popular posts from this blog

Python – Functions

What is Django in python?

What do you learn about Python?