Basic Lesson01 of the Python introductory course

Source: Internet
Author: User

  1. The difference between print 2.7 and 3.0 is  2.0  ===> print "Hello World"  3.0 ===>  print ("Hello World")

     1print("helloWorld")
  2. Variable assignment  temporarily stores data
    '  - '  =print(name,age)

  3. Input values are stored with variables.

    #                       3.0 input is input ("Please input your text")#                      2.X version there is raw_input ("Please input your text")  #                      2.7 in Input  () in parentheses what type of output will be given, and then the egg, 3.0 removed #                      3.0 If you want to use input ()  eq:eval (Input ("yous text") in 2.7)= input ("Please Your Nick name")print(name)
  4. If ... else ...  Indent eq:  int (var): turn var to int
    lucknum = Int (input ("Please input your luck number"))         ifLucknum = = 1:            Print("I want say no")         elifLucknum > 10:            Print("no come on baby")         Else:             Print("finally say yes")

  5. While loop
    Inputnum =0bingoNum= 13Count=0 whileCount < 3: Inputnum= Int (Input ("Please input yours num:")) Count= Count+1if(Count ==3):        Print("try too many")         Break    if(Inputnum >bingonum):Print("input number is bigger!")    elif(inputnum<bingonum):Print("input number is small!")    elif(Inputnum = = 13):        Print("Congratulation")     Break

  6. string concatenation   %s table placeholder   %s ... Assignment% (val ...) Company = input ("conpany:")
    Company = input ("Conpany:") Companynum= Input ("Number :")Print("info:\n Company"+company+"\nnumber"+companynum)#the "+" stitching string requires a separate memory for each additionPrint("info{} \ n Company:%s \ n Number:%s"% (company, Companynum))#no separate space to save memory

  7. String method
    TestString ="Testsss1"Print(Teststring.lower ())#Change LowercasePrint(Teststring.upper ())#Change CapitalizationPrint(Teststring.split ("g"))#use "G" to splitPrint(Teststring.count ("s"))#Count the number of "s"Print(Teststring.replace ("1","2"))

  8. Use of list lists
    NameList = ['Jerry','Tom','Jeck','Alice']Print(NameList)Print(Namelist[1])#Take valueNamelist.append ("Jerry")Print(NameList)#trailing Add dataPrint(Namelist.index ("Jerry"))#find Jerry's index valuePrint(Namelist.count ("Jerry"))#The statistics list contains the count of the stringnamelist.insert (0,"Lulu")#inserting data based on an indexPrint(NameList) namelist.sort ()Print(NameList)#Sort by askii code.Namelist.reverse ()#Reverse FlashbackPrint(NameList)Print(Len (NameList))#len (list) Gets the list lengthPrint(dir (list))#See what methods are available for list

  9. List Advanced
    NameList = [1,2,4,'OK','Yes']Print(Namelist[0:2])#The result is "0" and 2 for the index.Print(Namelist[0:2:2])#That means you can cut from 0~2 2.Print(Namelist[-3])#take the back and take it backwards.Print(namelist[-2:])#like taking out OK and yesPrint(Range (10))#Range (0, ten)Print(Type (range (10)))#results <class ' range ' >if4inchNameList:Print("Is true")#Determines whether the list contains a value
  10. Meta-group
    # Yuanzu = (1,3,4,5,5,6,)  two methods  count and index  list and tuple can be converted  to each other = (1,3,4,5,5,6,) list ( Yuanzu) type (yuanzu)    # result is listtuple (yuanzu) type (yuanzu)    #  The result is a tuple

  11.  operator 
     #   1.  * * Power 2**3 2 three-time square  #   2.  Divisible 1//2 =0 2//2=0 2.X  #   3.   2.X <> Not equal to 3.X remove  #   4. and Java and meaning  Or or not non-true  #   5.Is and IsNot type (list) is List Result true  

     

  12. Continue jump out of this cycle and continue to the next cycle
     for  in range:     if i > 3:         continue     print  1 2 3

    This article is only for learning reference, if there is no wrong please correct me, I am still a pupil, need to learn a lot of things, if reproduced please indicate the source

Basic Lesson01 of the Python introductory course

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.