Created
May 8, 2018 06:17
-
-
Save ImSingee/b7847d65d0e75809d769fca3d5a007e9 to your computer and use it in GitHub Desktop.
取出一段字符串前端的数字
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_head_number(s): | |
m = '' | |
for i in s: | |
if i.isdigit(): | |
m += i | |
else: | |
break | |
if m == '': | |
return None | |
else: | |
return int(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment