How to use Python from _ _ future__ import print_function
This article mainly introduces "how to use Python from _ future__ import print_function". In daily operation, I believe many people have doubts about how to use Python from _ future__ import print_function. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use Python from _ future__ import print_function"! Next, please follow the editor to study!
After adding the sentence from _ _ future__ import print_function at the beginning, even in python2.X, you have to use print in parentheses like python3.X. Parentheses are not required for print in python2.X, but are needed in python3.X.
# python2.7
Print "Hello world"
# python3
Print ("Hello world")
If a new feature appears in a version, and it is not compatible with the one used in the current version, that is, it is not a language standard in that version, then I need to import it from the future module if I want to use it.
Other examples:
From _ _ future__ import division
From _ _ future__ import absolute_import
From _ _ future__ import with_statement . Wait
Plus these, if your version of python is python2.X, you have to use these functions as python3.X does.
At this point, the study on "how to use Python from _ future__ import print_function" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!