I was trying to make a list in python looking like this;
['Product 1','Product 2','Product 3'......all the way to 10]
So far I've tried
[x for x in list(np.arange(1,11)) 'Product'+x ]
Is there a neat way of doing this?
I would do this.
[f"Product {x}" for x in range(1,11)]
["Product " + str(x) for x in range(1, 11)]
I prefer f strings, so I would do it:
[f'Product {i}' for i in range(1, 11)]
You can do it without f strings as well by casting the int to a string:
['Product ' + str(i) for i in range(1, 11)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.