Generate string of numbers python

前端 未结 2 799
误落风尘
误落风尘 2020-12-11 16:51

Hello I want to create a list of strings where each string is a number.

Fox example given the number 4 I would like to create a function that returns a list with ele

相关标签:
2条回答
  • 2020-12-11 17:42

    map being frowned upon by many python developers, here is the comprehension list equivalent:

     [str(x) for x in range(my_value + 1)]
    
    0 讨论(0)
  • 2020-12-11 17:44

    You can do this with str and range like this

    map(str, range(number + 1))
    

    When number = 4,

    print(map(str, range(4 + 1)))
    # ['0', '1', '2', '3', '4']
    
    0 讨论(0)
提交回复
热议问题