Adding spaces to items in list (Python)

前端 未结 7 1913
北海茫月
北海茫月 2020-12-19 10:12

I\'m a Python noob and I need some help for a simple problem.

What I need to do is create a list with 3 items and add spaces before and after every item.

For

7条回答
  •  感情败类
    2020-12-19 10:31

    >>> lst = ['a', 'bb', 'c']
    >>> 
    >>> [' {} '.format(x) for x in lst]
    [' a ', ' bb ', ' c ']
    >>> 
    

提交回复
热议问题