本文介绍了Python将字符串拆分为多个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复: 将字符串分割成Python列表
Possible Duplicate: Split string into a list in Python
我的字符串中包含很多部分字符串
I have a string with a lot of part-strings
>>> s = 'str1, str2, str3, str4'现在我有一个类似下面的功能
now I have a function like following
>>> def f(*args): print(args)我需要的是将我的字符串分成多个字符串,以便我的函数打印出这样的内容
what I need, is to split my string into multiple strings, so that my function prints something like this
>>> f(s) ('str1', 'str2', 'str3', 'str4')有人对我有想法吗?
- 我没有搜索将字符串拆分为字符串数组的函数.
- edit: I did not searched a function to split a string into an array of Strings.
这是我搜索的内容.
>>> s = s.split(', ') >>> f(*s) ('str1', 'str2', 'str3', 'str4')推荐答案
您可以使用split()拆分字符串.语法如下...
You can split a string by using split(). The syntax is as follows...
stringtosplit.split('whattosplitat')
要在每个逗号和空格处分隔示例,应为:
To split your example at every comma and space, it would be:
s = 'str1, str2, str3, str4' s.split(', ')更多推荐
Python将字符串拆分为多个字符串
发布评论