Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-01 18:24:16 10月04日 Update

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.

Tags: Code condition content different two memory object effect file run same variable address sequence situation more knowledge article industry statement Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology Microsoft MySQL Docker