Python Foundation One

Source: Internet
Author: User

First, comments

1 #!/usr/bin/env python2 #created by Baird3 4 #single-line comment5 6 " "Multi-line comments" "7 8 """Multi-line comments"""9 TenName ="Baird" OneName2=name A Print(name,name2) -  -Name ="Pencil" the Print(name,name2)

Ii. Branches and loops

1 #!/usr/bin/env python2 #created by Baird3 4  forIinchRange (0,10,2):#where 0 positions are closed, 10 is open and 2 is incremental5     Print("Loop", i)6 7Age = 578Count =09 Ten  whileCount < 3: Oneguess_age = Int (input ("Guess Age:")) A     ifguess_age==Age : -         Print("yes,you got it!") -          Break the     elifGuess_age>Age : -         Print("too Big") -     Else: -         Print("too small") +Count = count+1 - Else:#executes when the loop ends normally, i.e. non-break jumps +     Print("You ' ve tried too many times!")

Iii. input and format output

1 #!/usr/bin/env python2 #created by Baird3 4Name = input ("Name:")5age = Int (input ("Age :"))#strong turn into integral type6Job = input ("Job:")7Salary = input ("Salary:")8 9info =" "Ten ------------Info of" "+name+" "------------ One Name:" "+name+" " A Age :" "+STR (age) +" "A string is required to connect #使用 + number - Job:" "+job+" " - Salary:" "+Salary the Print(Info) -  -Info2 =" " - ------------Info2 of%s------------ + name:%s - age:%d + job:%s A salary:%s" "%(name,name,age,job,salary) at Print(Info2) -  -Info3 =" " - ------------Info3 of {_name}------------ - Name:{_name} - Age:{_age} in Job:{_job} - Salary:{_salary}" ". Format (_name=name,_age=age,_job=job,_salary=salary) to  + Print(INFO3) -  theInfo4 =" " * ------------Info4 of {0}------------ $ name:{0}Panax Notoginseng Age:{1} - job:{2} the Salary:{3}" ". Format (name,age,job,salary) +  A Print(Info4)

Python Foundation One

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.