我有这段代码:
...
COMPANY = list(lines[30])
COMPANY = ''.join(COMPANY)
COMPANY = COMPANY.replace(",", "")
COMPANY = COMPANY.replace("\n", "")
COMPANY = COMPANY.split(" : ")
COMPANY[1] = COMPANY[1].lower()
...
我想知道我是否可以在一行中设置COMPANY
而不是上面五行。
答案 0 :(得分:2)
只需链接方法调用:
COMPANY = ''.join(list(lines[30])).replace(",", "").replace("\n", "").split(" : ")
COMPANY[1] = COMPANY[1].lower()
如果您不喜欢它的外观,可以将它分成多行:
COMPANY = ''.join(list(lines[30])) \
.replace(",", "").replace("\n", "") \
.split(" : ")
答案 1 :(得分:0)
我相信这应该有效:
COMPANY = ''.join(list(lines[30])).replace(",","").replace("\n","").split(" : ")
COMPANY[1] = CAMPANY.lower()