Cleanest way to obtain the numeric prefix of a string

后端 未结 9 1383
醉话见心
醉话见心 2021-01-07 19:21

What is the cleanest way to obtain the numeric prefix of a string in Python?

By \"clean\" I mean simple, short, readable. I couldn\'t care less about performance, a

9条回答
  •  花落未央
    2021-01-07 19:49

    You could use regex

    import re
    initialNumber = re.match(r'(?P\d+)', yourInput).group('number')
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题