Python 提取字符串中数字与非数字字符

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
    原文作者:fighting--sky
    原文地址: https://blog.csdn.net/u012720518/article/details/107332683
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞