Python Learning four-day--for loop

Source: Internet
Author: User

A Python for loop can traverse any sequence of items, such as a list or a string.

Grammar:

The syntax format for the For loop is as follows:

For in sequence: statements(s)      

# !/usr/bin/env python # -*-coding:utf-8-*-  for  in range (1,100):    print (i)

Good memory as a dictionary, preview the dictionary in advance, where the dictionary is similar to the key value of Redis.

#!/usr/bin/env python#-*-coding:utf-8-*-Goods = [{"name":"Computer"," Price": 6000},{"name":"Game Consoles"," Price": 3000},{"name":"Beauty"," Price": 100000},{"name":"Fan"," Price": 99},{"name":"Socket"," Price": 19},{"name":"Kettle"," Price": 90},{"name":"Mobile Phone"," Price": 999},] forIinchGoods:Print(i)
For use cases
Use the List.append () module to output the number.
#!/usr/bin/evn python#-*-coding:utf-8-*-#Output 2 to 100 simple prime numbersPrime = [] forNuminchRange (2,100):#iterate numbers between 2 and 100    forIinchRange (2,num):#based on the factor iteration      ifNum%i = = 0:#determining the first factor          Break            #Jump out of the current loop   Else:#the else part of the loopprime.append (num)PrintPrime




Python learning four-day--for loop

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.