Python26_ to participate in the program pass a list of formula

Pass parameters to the program

If you want to be able to receive their own parameters passed in the program, you need to add in the program

import sys
print(sys.argv) #打印出给程序传递的所有参数。注意:第一个参数总是程序的名字

List of Formula

range () Notes :

  1. range () method returns is a list (of python2)
  2. In python2 the range What are the risks?
    1. If you want a lot of memory, the system may not give. Or occupy a large memory space but forgot to use the space would have been occupied

For python3: What a time to value, generates a return value. That return is no longer list. This is with a very small memory to solve this problem.

List of Formula

a = [i for i in range(100)]
b = [j for j in range(100) if j%2 == 0]
c = [i for i in range(3) for j in range(2)] #c = [0,0,1,1,2,2]  循环嵌套
#相当于
c = []
for i in range(3):
    for j in range(2):
        c.append(i)
d = [(i,j) for i in range(3) for j in range(2)] #d = [(0,0),(0,1),(1,0),(1,1),(2,0),(2,1)]

Guess you like

Origin blog.csdn.net/qq_34873298/article/details/90719601