亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python中的拆分函數以將字符串與逗號分開

python中的拆分函數以將字符串與逗號分開

慕婉清6462132 2022-06-02 16:23:21
如何使用 split'g5s,12-04-2019'與逗號分隔。a='g5s,12-04-2019'如果在拆分之后b = 'g5s',我會搜索結果c='12-04-1=2019'
查看完整描述

2 回答

?
素胚勾勒不出你

TA貢獻1827條經驗 獲得超9個贊

str.split()救援:


a='g5s,12-04-2019'

b, c = a.split(",")


查看完整回答
反對 回復 2022-06-02
?
陪伴而非守候

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=, 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.


查看完整回答
反對 回復 2022-06-02
  • 2 回答
  • 0 關注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號