"One" range () function
You can use the range () function in Python to produce a series of numbers
For W in Range (1,11):
print (W)
Output:
1
2
3
4
5
6
7
8
9
10
#注意: This is over by 10, not including 11.
"Two" list () function
If you pass range () as a parameter to the list () function, the number is output as a list
Num=list (range (1,11))
print (num)
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
You can also specify the step size when using the range () function
Num=list (range (1,11,2))
print (num)
Output:
[1, 3, 5, 7, 9]
The "three" min () function, the max () function, and the sum () function
Min () function for minimum value, max () function for maximum value, sum () function sum
Num=list (range (1,11,2) print (num) print (max) print (min.) Print (
"sum is:", sum (num))
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
10
1
Sum is:55
"Four" list resolution
List resolution is to reduce code raw code:
Num=[] for
W in range (1,11):
num4=w**2
num.append (num4)
print (num)
Output:
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
List Resolution code:
num1=[num2**3 for num2 in range (1,11)
print (NUM1)
Output:
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]