分割文本使用分割函数

2024-04-26 12:33:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在python3.6中拆分。你知道吗

我只需要abc-1.4.0.0

mytext = "_bla.blub = 'abc-1.4.0.0';"
#print(mytext)
mytext = str.split("_bla.blub = '");
#print (mytext)
print (mytext[1].split("'")[0])

但我的结果是空的。为什么?你知道吗


Tags: splitabcprintblastrmytextblub
3条回答

你实际上并不是在对mytext采取行动。你知道吗

请尝试以下操作:

mytext = "_bla.blub = 'abc-1.4.0.0';"
#print(mytext)
mytext = mytext.split("_bla.blub = '")
#print (mytext)
print (mytext[1].split("'")[0])

请执行以下操作:

mytext = "_bla.blub = 'abc-1.4.0.0';"
mytext = str.split(mytext);
mytext

['_bla.blub', '=', "'abc-1.4.0.0';"]

mytext[2]
"'abc-1.4.0.0';"

或者

mytext = "_bla.blub = 'abc-1.4.0.0';"

mytext = mytext.split("_bla.blub = '")

print (mytext[1].split("'")[0])
abc-1.4.0.0

或者

mytext = "_bla.blub = 'abc-1.4.0.0';"
mytext = mytext.split("'");
mytext

['_bla.blub', '=', "'abc-1.4.0.0';"]

mytext[1]
'abc-1.4.0.0'
mytext = "_bla.blub = 'abc-1.4.0.0';"
print(mytext)
mytext = mytext.split("'");
print (mytext)
print (mytext[0])
print (mytext[1])

您需要对字符串调用.split(),并将其保存到变量中,而不是对str类调用.split()Try this.

相关问题 更多 >