Python Learning day03

Source: Internet
Author: User

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

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.