Category: New Python tutorial

python tutorials and learn python

Created with Sketch.

What is NumPy

What is NumPy Summary: in this tutorial, you’ll have a good understanding of NumPy and how it helps you perform calculations fast and efficiently. Introduction to NumPy NumPy stands for Numerical Python and is pronounced as /ˈnʌmpaɪ/. Numpy is a Python library that performs numerical calculations. NumPy is very fast because it is written in…
Read more

Python NumPy

Python NumPy This Python NumPy Tutorial helps you learn NumPy from scratch so that you can use it effectively in your data science & machine learning projects. What you’ll learn Create single and multi-dimensional NumPy arrays Effectively use NumPy built-in functions & methods Perform mathematical operations on arrays Extract elements from arrays using slicing and…
Read more

Python unittest subtest

Python unittest subtest Summary: in this tutorial, you’ll learn how to define parameterized tests using unittest‘s subTest() context manager. Introduction to the unittest subtest context manager First, create a new module called pricing.py and define a calculate() function as follows: def calculate(price, tax=0, discount=0): return round((price – discount) * (1+tax), 2) Code language: Python (python)…
Read more

Python unittest Coverage

Python unittest Coverage Summary: in this tutorial, you’ll learn how to use the Python unittest coverage command to generate a test coverage report. What is test coverage? Test coverage is a ratio between the number of lines executed by at least one test case and the total number of lines of the code base: test…
Read more

Python Mock Requests

Python Mock Requests Summary: In this tutorial, you’ll learn how to mock the requests module in Python to test an API call using the unittest module. The requests module is an HTTP library that allows you to send HTTP requests easily. Typically, you use the requests module to call an API from a remote server.…
Read more

Python Stubs

Python Stubs Summary: in this tutorial, you’ll learn how to use Python stubs to isolate parts of your program from each other for unit testing. Introduction to the Python stubs Stubs are test doubles that return hard-coded values. The primary purpose of stubs is to prepare a specific state of the system under test. Stubs…
Read more

Python patch()

Python patch() Summary: in this tutorial, you’ll learn how to use the Python patch() to replace a target with a mock object temporarily. Introduction to the Python patch The unittest.mock module has a patch() that allows you to temporarily replace a target with a mock object. A target can be a function, a method, or…
Read more

Python Unittest Mock

Python Unittest Mock Summary: in this tutorial, you’ll learn about the Python unittest Mock class and how to use it to mock other classes. Introduction to Python unittest Mock class Mocks simulate the behaviors of real objects. To test an object that depends on other objects in an isolated manner, you use mock objects to…
Read more

Python assertIn()

Python assertIn() Summary: in this tutorial, you’ll learn how to use the Python assertIn() method to test if a member is in a container. Introduction to the Python assertIn() method The assertIn() is a method of the TestCase class of the unittest module. The assertIn() method tests if a member is in a container: assertIn(member,…
Read more

Python assertTrue()

Python assertTrue() Summary: in this tutorial, you’ll learn how to use Python assertTrue() to test if an expression is True and assertFalse() method to test if an expression is False. Introduction to the Python assertTrue() method The assertTrue() is a method of the TestCase class in the unittest module. The assertTrue() method tests if an…
Read more