Warnings are provided to warn the developer of situations that aren’t necessarily exceptions. Usually, a warning occurs when there is some obsolete of certain programming elements, such as keyword, function or class, etc. A warning in a program is distinct from an error.
# program to display warning a message import warnings print('Hello') # displaying the warning message warnings.warn('Warning Message: 4') print('Hello !')
Hello main.py:8: UserWarning: Warning Message: 4 warnings.warn('Warning Message: 4') Hello!