我有几个这样的字母数字string listOfNum = ['000231512-n','1209123100000-n00000','alphanumeric0000', '000alphanumeric'] 消除尾随零的所需输出将是: listOfNum = ['000231512-n','1209123100000-n','alphanumeric', '000alphanumeric'] 前导零的期望输出是: listOfNum = ['231512-n','1209123100000-n00000','alphanumeric0000', 'alphanumeric'] 去除前导零和后缀零的欲望输出将是: listOfNum = ['231512-n','1209123100000-n00000','alphanumeric0000', 'alphanumeric'] 现在我已经这样做了,请build议一个更好的方法,如果有: listOfNum = ['000231512-n','1209123100000-n00000','alphanumeric0000', \ '000alphanumeric'] trailingremoved = [] leadingremoved = [] bothremoved = [] # Remove trailing for i in listOfNum: while i[-1] == "0": i = i[:-1] trailingremoved.append(i) # Remove leading for i […]
为什么Python 3允许“00”作为0的文字而不允许“01”作为1的文字呢? 有没有很好的理由? 这种不一致让我感到困惑。 (而且我们正在谈论Python 3,它有意破坏了后向兼容性,以实现一致性等目标。) 例如: >>> from datetime import time >>> time(16, 00) datetime.time(16, 0) >>> time(16, 01) File "<stdin>", line 1 time(16, 01) ^ SyntaxError: invalid token >>>
我有一个sqlite表中有三列: Column1 Column2 Column3 A 1 1 A 1 2 A 12 2 C 13 2 B 11 2 我需要selectColumn1-Column2-Column3 (例如A-01-0001 )。 我想填充每个列- 我是SQLite的初学者,任何帮助将不胜感激