如何使用 split'g5s,12-04-2019'与逗号分隔。a='g5s,12-04-2019'如果在拆分之后b = 'g5s',我会搜索结果c='12-04-1=2019'
2 回答

陪伴而非守候
TA贡献1757条经验 获得超8个赞
您应该使用x.split()并传递逗号作为输入参数,就像这样x.split(",")。这意味着输入参数是分隔符。
该split方法返回一个单独包含元素的列表。你可以一一解开。像这样:b, c = a.split(",")
代码:
a = "g5s,12-04-2019"
print("a={a}".format(a=a))
b, c = a.split(",")
print("b={b}, c={c}".format(b=b, c=c))
输出:
>>> python3 test.py
a=g5s,12-04-2019
b=g5s, c=12-04-2019
供参考:
方法的文档字符串split。
S.split(sep=None, maxsplit=-1) -> 字符串列表
Return a list of the words in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.
添加回答
举报
0/150
提交
取消