Syntax: Assert condition [Error Message] Example 1: assert statement without error message Example 2: assert statement with error message Example 3: assert statement with try & except Example 4: assert statement with function Above, square(10) will return 100, whereas square(-10) will raise an AssertionError because we passed -10. Popular Posts
Iterables Iterators Iterators can be iterable because both iterator and iterable can be iterated using for loop but iterable objects can not be iterator because next() method is not supported by iterable objects. Popular Posts
Python implementation Generators Python generators are functions that are similar to normal functions, but use yield statements instead of return statements. A generator function returns the generator object with a sequence of elements, which we can iterate over. Element in a generator object can be accessed either by using the next() function or using a…
Abstract Class Why Abstraction is Important? In Python, a person usually abstracts data/classes to hide the irrelevant information. This helps to reduce complexity and increase application efficiency. Abstract Base Classes An abstract class is the first part of a development interface that can be used to apply common features and behavior to several related subclasses.…
Object-oriented programming (OOP) is a programming paradigm based on the concept of objects which contains data or attributes and code or methods. Major oops concepts include Class, Object, Inheritance, Polymorphism, Data Abstraction, Encapsulation. Class Class is the user defined data type and it is defined using class keyword. It is a collection of similar type…
Python functions A function is a construct that helps us perform some action using a block of code (the body of the function), sometime based on input parameters. These functions can take different forms and can do a lot to allow your functional code base to be effective, To define a function, you use the…
As we have learned for loop to walk through a sequence, and do something with each item, at least read some value from it. There is a scenario, similar to what we saw with the last example in the for-loop introduction, that involves making a new list from the result of doing an operation on…
1 – What is F1 score? F1 score is a measure of the accuracy of a model. It is defined as the harmonic mean of precision and recall. F1 score is one of the most popular metrics for assessing how well a machine learning algorithm performs on predicting a target variable. F1 score ranges from…
The if and else clause are used to structure our code with checks for conditions. The if statement is followed by an expression that we use to express a condition, and delimiters the so-called if block. The block is executed if and only if the expression evaluates to True. Example 1: By the way, even…
There are many type of different operations using operators in the language: Identity As we manipulate values (using variable), two values can have the same identity. This can be tested using special built-in function: id(). We use is as the identity comparison operator, and the result here shows that var and the var3 have the…
Now let’s discover data types that we can use to manipulate more data and do more things, such as lists, sets, and dictionaries. Lists A list is a sequence of arbitrary objects. You remember we said that strings are a sequence of (text) characters, so some of the things we already seen about strings apply…
Let’s quickly explore the first tools and basic syntax rules for a beginner to start using Python. But before that, know that when needed, you can find documentation on the Python.org site and many online resources, including sites like StackOverflow. Printing things We use the print() function to print stuff in Python. This is essential…