Python efficiently split currency sign and number in one string

前端 未结 6 882
一生所求
一生所求 2021-01-16 07:04

I have a string like \'$200,000,000\' or \'Yan300,000,000\'

I want to split the currency and number, and output a tuple (\'$\', \'200

6条回答
  •  无人共我
    2021-01-16 07:07

    You can use regex for this.

    p1 = re.compile("\d")  #match digits
    p2 = re.compile("\D")  match non-digits
    
    
    currency_symbol = p1.split(cur_str)[0]
    value = int("".join([group for group in p2.split(cur_str)]))
    

提交回复
热议问题