python中的拆分函数以将字符串与逗号分开

如何使用 split'g5s,12-04-2019'与逗号分隔。

a='g5s,12-04-2019'如果在拆分之后b = 'g5s',我会搜索结果c='12-04-1=2019'


慕婉清6462132
浏览 139回答 2
2回答

素胚勾勒不出你

str.split()救援:a='g5s,12-04-2019'b, c = a.split(",")

陪伴而非守候

您应该使用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-2019b=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.
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python