Python if,for,while

Source: Internet
Author: User

#-*-coding:utf-8-*-#Fourth Chapter if for while#Boolean logicPrintTrue = =FalsePrintTrue andFalsePrintTrueorFalsePrint  notTruePrintTrue! =False#if elif elseName ='Lee'ifName = ='Chen' :    Print 'Yes, you are Chen'elifName = ='le':    Print 'Yes, you are God'elifName = ='Shou':    Print 'No, get out'#a conditional expression, similar to an expressionPrint 'Yes' if1 + 1 = = 2Else 'No'# for#RangePrintHelp (range)PrintType (range (10))PrintRange (0, 10, 2)PrintRange (10, 0, 1)#Range (Start, Stop=none, Step=none) step is each increment or decrement (-) Step forIinchRange (10, 0, 1) :    PrintI forIinch[' A',' at','Lala'] :    PrintI# whileName ='Chen' whileTrue:Print 'Heheda'    ifName = ='le' :         Breakname='le'    Continue    Print "no continue"

Results:

Falsefalsetruefalsetrueyeshelp on built-inchFunction rangeinchModule__builtin__: Range (...) Range (stop)-List of integers range (start, stop[, step])-List of integers Return a list containing an arithmetic progression of integers. Range (I, j) returns [I, I+1, I+2, ..., j-1];    Start (!) defaults to 0. When step isGiven, it specifies the increment (ordecrement). For example, range (4) returns [0, 1, 2, 3]. The end point isomitted! These is exactly the valid indices forA list of 4elements. None<type'List'>[0,2, 4, 6, 8][10, 9, 8, 7, 6, 5, 4, 3, 2, 1]109876543211223Lalahehedaheheda

For or while else
# While or for else # The loop ends normally (no break, return), and else is entered in the Else code snippet.  for  in range:    print     iif i = = 3 :        break  Else  :    print"forelse"

Results:

0123

Python if,for,while

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.