In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the python commonly used conditional judgment statement block is what the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, with a certain reference value, I believe you will get something after reading this python commonly used conditional judgment statement block, let's take a look at it.
Python commonly used conditional judgment statement block if _ _ name__ = ='_ _ main__'.
Create a new python file named py3_main.py, and write the operation code in this file:
# Today, learn the # common conditional judgment statement in python # if _ _ name__ = ='_ _ main__'# to check whether the python custom module is run directly or imported into other modules # Let's print the name directly: print ("py3_main module's name: {}" .format (_ _ name__)) # the result is: # py3_main module's name: _ _ main__# where _ _ name__ is a special variable in python
Create a new python file named py3_module.py:
# We import py3_mainimport py3_main# here we run the program found # output result is: # py3_main module's name: py3_main# because py3_main is imported module # _ _ name__ is py3_main# continue to print the nameprint of this module ("py3_module module's name: {}" .format (_ _ name__)) # py3_module module's name: _ _ main__
We adjust the print statement in py3_main to add conditional judgment:
Def main (): print ("py3_main module's name: {}" .format (_ _ name__))
# determine whether the module is imported or run directly by the condition: # to run the main () function
If _ _ name__ ='_ _ main__': main () else: print ("run module's name: {}" .format (_ _ name__))
Then, after re-executing the code of py3_module.py, it is found that the running result is:
Run module's name: py3_mainpy3_module module's name: _ _ main__
With if _ _ name__ = ='_ _ main__', we can control when the code in the module is executed, similar to the main methods of other programming languages such as java.
This is the end of the article on "what is the block of conditional judgment statements commonly used in python?" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what is the conditional judgment sentence block commonly used in python". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.