请问如何用简单的方法生成 a1，a2，....，a20 这样的序列

https://stackoverflow.com/questions/293395...

`` ['a{}'.format(i) for i in range(1, 20)]``

R中的很简单：

``paste('a',1:20,sep='')``

``````[f'a{i}' for i in range(20)]

``````>>> def paste(head, start=0, stop=0, step=1, sep=''):
...     return [f'{head}{sep}{i}' for i in range(start, stop, step)]
...
>>> paste('a', 0, 10)
['a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9']
>>> paste('a', 9, -1, -1)
['a9', 'a8', 'a7', 'a6', 'a5', 'a4', 'a3', 'a2', 'a1', 'a0']
>>> paste('a', 0, 10, sep='-')
['a-0', 'a-1', 'a-2', 'a-3', 'a-4', 'a-5', 'a-6', 'a-7', 'a-8', 'a-9']``````
1周前 评论
TNT_God 1周前

``````[f'a{i}' for i in range(20)]

``````>>> def paste(head, start=0, stop=0, step=1, sep=''):
...     return [f'{head}{sep}{i}' for i in range(start, stop, step)]
...
>>> paste('a', 0, 10)
['a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9']
>>> paste('a', 9, -1, -1)
['a9', 'a8', 'a7', 'a6', 'a5', 'a4', 'a3', 'a2', 'a1', 'a0']
>>> paste('a', 0, 10, sep='-')
['a-0', 'a-1', 'a-2', 'a-3', 'a-4', 'a-5', 'a-6', 'a-7', 'a-8', 'a-9']``````
1周前 评论
TNT_God 1周前

@Jason990420 谢谢大佬。

1周前 评论