直接上代码:

片段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

 

相关文章:

  • 2021-11-24
  • 2022-02-04
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
  • 2021-04-28
  • 2021-08-30
猜你喜欢
  • 2022-12-23
  • 2021-06-06
  • 2021-08-09
  • 2022-12-23
  • 2022-03-11
  • 2021-06-01
  • 2022-12-23
相关资源
相似解决方案