陪伴而非守候
您应该使用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.