直接上代码:
片段1:
>>> def func(x): print ( ' , ' .join(str(i) for i in range(1,x+1 ))) >>> func(5 ) 1,2,3,4,5 >>> func(10 ) 1,2,3,4,5,6,7,8,9,10
片段2:
>>> def func(x): for i in range(1,x+1 ): print ( ' , ' .join(str([j, ' password ' ][j==i]) for j in range(1,x+1 ))) >>> func(10 ) password, 2,3,4,5,6,7,8,9,10 1,password,3,4,5,6,7,8,9,10 1,2,password,4,5,6,7,8,9,10 1,2,3,password,5,6,7,8,9,10 1,2,3,4,password,6,7,8,9,10 1,2,3,4,5,password,7,8,9,10 1,2,3,4,5,6,password,8,9,10 1,2,3,4,5,6,7,password,9,10 1,2,3,4,5,6,7,8,password,10 1,2,3,4,5,6,7,8,9,password