Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The condition of python determines what the operation of if, elif and else looks like.

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about the conditions of python to judge what the operation of if, elif and else is like. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Today learn the conditional judgment of python if, elif, else operation.

First, create a new python file named py3_cond.py, and write the operation code in this file (the following is the code, which shows the running effect):

# simple if statement # judged to be true to execute code block content if True: print ("eager to learn Python!") # because it is False, if False: print ("not printed here") # A complete if elif else# code block lang = 'Python'#lang =' Java'if lang = = 'Python': print ("Hello" + lang) elif lang = =' Java': print ("Hello") + lang) elif lang = = 'Go': print ("Hello" + Go) else: print ("No Match!") # use and or not# for conditional judgment # and operation user =' yale'login_in = Trueif user = = 'yale' and login_in: print (' admin logins') else: print ('common logins') # or operation user = 'yale'login_in = Trueif user = =' yale' or login_in: print (' Admin logins') else: print ('common logins') # not operation login_in = Falseif not login_in: print ('Please logins') else: print ('login logins') # compare lista = [1 Magi 2 3] b = [1 id 2) 3] print (a = = b) # Trueprint (an is b) # False# because a b is two different objects in memory # the addresses of two variables are different print (id (a)) print (id (b)) # in the following case, it would be Truea = [1jue 2 3] b = aprint (id (a)) print (id (b)) # True# is the same object in memory print (an is b) # Python defaults to the value of False # False# None# "any empty sequence or list For example:'', (), []. # any empty mapping, for example: {} condition = Falseif condition: print ('True values') else: print (' False values')

The running effect of the above code:

After reading the above contents, do you have any further understanding of the condition of python to judge the operation of if, elif and else? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report