How does if __name__ == "__main__": works?

My fellow mate shared a code of Python that contains a statement like if __name__ == "__main__":. I saw it for the very first time and did not get what functionality this statement provides. Here’s a code below:

Kindly someone explains what `if __name__ == "__main__":` do in general as well as in the above-provided code?