Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,如果字符串是:"1\t2\t3\t\t4"
"1\t2\t3\t\t4"
它可以返回如下列表:['1', '2', '3', None, '4']
['1', '2', '3', None, '4']
[x or None for x in "1\t2\t3\t\t4".split("\t")] #>>> ['1', '2', '3', None, '4']
如果你真的想要ints 在你的例子中:
int
[int(x) if x else None for x in "1\t2\t3\t\t4".split("\t")] #>>> [1, 2, 3, None, 4]