In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.