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