Python Basic 2.1 If Process Control (i)

Source: Internet
Author: User

I. If Else1.if StatementsIf expression://Note If there is a colon after, there must be Statement (s)//4 spaces relative to if indent Note: Python uses indentation as a method of grouping its statements, and it is recommended to use 4 spaces2. Example:1 "[email protected] python-scripts]# cat 11.py#!/usr/bin/python#coding =utf-8if 1: //In Python 1 is true (true), 0 is False (fluse) print "Hello python" //when it is true output "Hello python" Else:print "Hello Linux" //otherwise output "Hell Linux" Run as follows:[[email protected] python-scripts]# python 11.pyHello python2 "[email protected] python-scripts]# cat 11.py#!/usr/bin/python#coding =utf-8if 0: The print "Hello python" statement is executed only when the condition is set, otherwise print "Hell Linux" is executedprint "Hello python"Else:print "Hello Linux"Run as follows:[[email protected] python-scripts]# python 11.pyHello Linux 3 "[email protected] python-scripts]# cat 11.py#!/usr/bin/python#coding =utf-8if 1 < 2://1 less than 2 is established, the following statement is executedprint "Hello python"Else:print "Hello Linux"The results of the operation are as follows:[[email protected] python-scripts]# python 11.pyHello python4 "[email protected] python-scripts]# cat 11.py#!/usr/bin/python#coding =utf-8a = (' B ', +)if ' B ' in a:print "Hello python"Else:print "Hello Linux"Run as follows:[[email protected] python-scripts]# python 11.pyHello python5 "[email protected] python-scripts]# cat 11.py#!/usr/bin/python#coding =utf-8if not 1 > 2: // negateprint "Hello python"Else:print "Hello Linux"Run as follows:[[email protected] python-scripts]# python 11.pyHello python6 "[email protected] python-scripts]# cat 11.py#!/usr/bin/python#coding =utf-8if not 1 > 2 and 1==1:print "Hello python"Else:print "Hello Linux"[[email protected] python-scripts]# python 11.pyHello python3.if Statement Exercise: Here is the input [email protected] python-scripts]# cat 12.py#!/usr/bin/python#coding =utf-8sorce = input("Please input a num:") if Sorce >=:print "A"print "Very good"elif sorce >=80:print ' B 'print ' good 'elif sorce >=70:print ' Pass 'Else:print ' not pass '4.int Usagein [1]: Int (' + ') //30 is a string, and it becomes a number by int Out[1]:In [2]: type (int (') )out[2]: int //type is shaped 5.if Practice, here with Raw_input [email protected] python-scripts]# cat 12.py#!/usr/bin/python#coding =utf-8sorce = int(raw_input("Please input a num:")) //Use raw_input here to turn the quoted numbers into plastic if Sorce >=:print "A"print "Very good"elif sorce >=80:print ' B 'print ' good 'elif sorce >=70:print ' Pass 'Else:print ' not pass '

Python Basic 2.1 If Process Control (i)

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.