In Python, how do I create a string of n characters in one line of code?

前端 未结 6 1352
梦毁少年i
梦毁少年i 2020-12-02 11:58

I need to generate a string with n characters in Python. Is there a one line answer to achieve this with the existing Python library? For instance, I need a string of 10 l

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 12:18

    If you can use repeated letters, you can use the * operator:

    >>> 'a'*5
    
    'aaaaa'
    

提交回复
热议问题