Re-learning Python-day 03-python Basic And while loop instance + Continue && Break application + List of initial learning

Source: Internet
Author: User

application of the while statement

Examples are as follows:

1 """2 User Login system, can only log in at most three times3 after the third failure, the program terminates4 5 """6User_table = {"python":"Important","Java":"more_important","Shell":"Linux"}7Time = 18 9  whileTime < 4:Tenuser_name = input ("Please enter your user name:") OneUser_password = input ("Please enter your password:") A     ifUser_nameinchUser_table.keys () andUser_passwordinchUser_table.values ():#very low, because the user name and password can be mixed, and later update it -         Print("welcome,master!! ") -          Break the     Else: -         Print("You failed login system!!") -         ifTime = = 3: -             Print("Three chances is all userd!!") +Time + = 1

Ps:1. The results of the run do not show

2. I choose the IDE is pycharm, registration code own Baidu keyword: pycharm 2017 registration Code (self-study can be used, but to the regular company Don't Mess with)

Understanding and examples of continue and break statements

Continue: The current cycle jumps out and continues the next loop

Break: Jump out of the current entire loop

1Flag =False2  forIinchRange (10):3     ifI < 6:4         Continue  #0 to 5 is skipped, the print statement behind it cannot be executed5     Print(i)#When i = 6, start printing6      forJinchRange (10):7         Print(j)8         ifj = = 5:9Flag =TrueTen              Break  #interrupts the current loop, and the second for loop is interrupted One     #If flag: A     #break cancels the comments on both lines, the first for loop is interrupted and can be judged according to the format

Python Classic data Type--list

Example:

1List1 = ["a","b","C","e","F","D"]2 3 Print(List1[3])#the first index, not the left or right, is the default index value from the left, and the following index example is4 Print(list1[1:])#The first value to the last value5 Print(List1[1:-1])#-1 is the second-lowest value6 Print(List1[::-1])#The list is reversed. -1 means go from right to left7 Print(list1[4::-1])8 Print(List1)9 Ten  One #List Modification AList1.append ("python") - Print(List1) -  the #to modify a value at a specified location -LIST1[2] ="Java" - Print(List1) -  + #Insert -List1.insert (1,"Ruby") + Print(List1) A  at #Remove a method remove del pop -List1.remove ("Java")#You can also specify a value with an index, List1.remove (list[1]) - Print(List1) -List1.pop (2) - Print(List1) - delList1[1] in Print(List1)

Operation Result:

e['b','C','e','F','D']['b','C','e','F']['D','F','e','C','b','a']['F','e','C','b','a']['a','b','C','e','F','D']['a','b','C','e','F','D','python']['a','b','Java','e','F','D','python']['a','Ruby','b','Java','e','F','D','python']['a','Ruby','b','e','F','D','python']['a','Ruby','e','F','D','python']['a','e','F','D','python'] The process has ended, exit code 0

PS: List of built-in functions put on tomorrow's notes

Re-learning Python-day 03-python Basic And while loop instance + Continue && Break application + List of initial learning

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.