The difference between print 2.7 and 3.0 is 2.0 ===> print "Hello World" 3.0 ===> print ("Hello World")
1print("helloWorld")
Variable assignment temporarily stores data
' - ' =print(name,age)
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)
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")
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
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
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"))
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
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
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
-
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
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