Python | Warnings | Introduction

Python | Warnings | Introduction

The Warning Module was introduced to warn the programmers about changes in library features.

Warning messages are issued while running the program to alert the user when the user uses the obsolete module in the program.

Warnings do not terminate the program but raise an exception when running the program.
In Python, the warning is issued by calling the 'warn()' function.

Sample Program:

import warnings print("Cppsecrets") warnings.warn('This is a warning message') print("Cppsecrets")

Cppsecrets <string>:4: UserWarning: This is a warning message Cppsecrets

Here we can see in the OUTPUT that even after the warning message is displayed, the program continued to run till the end of the program.