One:
1: For loop
for in range (3): print(i);
Login Applet
_username ="Duke"; _password="123456"; forIinchRange (3): Username= Input ("Username:"); Password= Input ("Password:"); ifUsername = = _username andPassword = =_password:Print("Welcome%s Login ..."%_username); Break; Else: Print("Invalid username or password!");
2: while loop
_username ="Duke"; _password="123456"; counter= 1; whileCounter <= 3: Username= Input ("Username:"); Password= Input ("Password:"); ifUsername = = _username andPassword = =_password:Print("Welcome%s Login ..."%_username); Break; Else: ifcounter==2: Print("you only have one chance today! ") Print("Invalid username or password!"); Counter+ = 1;
Two: The operation of the list
a= ['Join','Xiaohua','Xinxin','Huanuhan']#value of the queryPrint(a[0])#Index MethodPrint(A.index ('Join'))#Take out the subscript for the element you want to find#slicesPrint(A[1:-1])#take the one to the bottom.Print(a[1:])#take all from the beginningPrint(A[0::2])#Plus compensation 2, that is, the interval for the number of 2, that is, skipping a#note that when the last number is negative, the direction to go is to go back#AddA.append ("Wangwang");Print(a);#InsertA.insert (1,"Minmin");Print(a);#Modify the value directly from the new assignmenta[5]="Gong";Print(a);#Delete#Remove MethodA.remove ("Gong")#Remove elements from list This example removes the element from list GongPrint(a);#Pop MethodB=a.pop (1)#Delete the element with subscript and print out the deleted elementPrint(b);#assign the value of the deletion to BPrint(a)#del methoddelA[1]#Delete the second element in List adelA#Delete List A object (that is, lists)#Count The number of occurrences of an elementc = A.count (" to");Print(c);#Extend MethodD= ['1','haha'];d. Extend (a);Print(d);#Sort method Sorting methods by ASCIIx = [1,6,4,9,3,7,2]x.sort ();Print(x);#Reverse method Inverse orderx.reverse ();Print(x);
Python Learning day03