how to use split to separete 'g5s,12-04-2019'
from comma.
I search for result if a='g5s,12-04-2019'
then after split b = 'g5s'
and c='12-04-1=2019'
how to use split to separete 'g5s,12-04-2019'
from comma.
I search for result if a='g5s,12-04-2019'
then after split b = 'g5s'
and c='12-04-1=2019'
You should use the x.split()
and pass the comma as input argument, like this x.split(",")
. It means the input argument is the separator.
The split
method returns a list which contain the elements separately. You you can unpack them one by one. Like this: b, c = a.split(",")
Code:
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))
Output:
>>> python3 test.py
a=g5s,12-04-2019
b=g5s, c=12-04-2019
FYI:
The docstring of the split
method.
S.split(sep=None, maxsplit=-1) -> list of strings
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.