import re
def func(s):
number = re.findall(r'\d+', '1TB')
unit = re.findall(r'\D+', '1TB')
print('number: ' + str(number[0]))
print('unit: ' + str(unit[0]))
if __name__ == '__main__':
s = '1TB'
func(s)
执行结果:
number: 1
unit: TB