>>> str = '''january
... february
... march
... april
... may
... june'''
>>> str.splitlines() # returns a list
['january', 'february', 'march', 'april', 'may', 'june']
>>> tuple(str.splitlines()) # you can convert to tuple like this
('january', 'february', 'march', 'april', 'may', 'june')
试试这个
执行程序,复制粘贴你的垂直字符串。你呢会得到
splitlines()
返回包含字符串中所有行的list
。你知道吗非常简单的方法,等待用户键入换行符。你知道吗
相关问题 更多 >
编程相关推荐