Python conditional statements and operators

Source: Internet
Author: User

If Else form

[Email protected] ~]$ VI testoperator.py#!/bin/python#operator testingnumber1=111number2=222if (NUMBER1>NUMBER2)  : Print ("num1>num2") else:print ("Num2>num1") str1= "AAA" str2= "BBB" if (STR1==STR2): Print ("STR1=STR2") Else: Print ("Str1!=str2") a=3b=2if (a>b): Print ("A>b") elif (a==b): Print ("A=b") else:print ("A<b")

The judgment condition of the IF statement can be expressed by > (greater than), < (less than), = = (equals), >= (greater than or equal), <= (less than or equal).

If judgment condition: Execute statement ... else: Execute statement ....

When judging a condition for multiple values, you can use the following form:

If judgment Condition 1: Execute statement 1......elif judgment Condition 2: Execute statement 2......elif judgment Condition 3: Execute statement 3......else: Execute statement 4 ...

Since Python does not support switch statements, multiple conditions can only be determined by elif, and if the judgment requires multiple conditions to be judged at the same time, the or (or) is used to indicate that two conditions have a successful condition when they are established; When using and (and), Indicates that only two conditions have been established at the same time, the judgment condition succeeds.

Three forms of looping, shell support, Python supports only while and for in forms

While judging condition: Execute statement ...
For Iterating_var in Sequence:statements (s)

The three expression syntax for a For loop is as follows: for (EXP1; EXP2; EXP3)) do Command1 Command2 Command3 done





Python conditional statements and operators

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.