Difference between __future__ and __main__ in Python
__future__ | __main__ |
---|---|
The __future__ module allows developers to enable new language features that are not compatible with the current version of Python being used. It is used to ensure that the code written today is forward-compatible with future versions of the Python interpreter. | The __main__ module is the entry point of a Python program. It is the module that is executed when the program starts running. It is commonly used to define the main execution logic of the program. |
The __future__ module is used to enable features from future versions of Python in the current version. It helps in writing code that is compatible with future versions of Python. | The __main__ module is used to define the main execution logic of a program. It contains the code that is executed when the program starts running. |
The __future__ module is imported using the import statement at the beginning of the code. | The __main__ module is identified by the __name__ variable having the value “__main__”. |
Example: from __future__ import division a = 5 / 2 print(a) Output: 2.5 |
Example: if __name__ == “__main__”: print(“This is the main module”) Output: This is the main module |
The __future__ module is commonly used to enable features like division operator behavior, print function, and other language changes. | The __main__ module is commonly used to define the main logic of a program and execute specific code when the program starts running. |