Python: Check if String Starts with Number
You can use the isdigit() method of strings to determine if a string starts with a number. Example is as follows:
s = "123abc"
if s[0].isdigit():
print("字符串以数字开头")
else:
print("字符串不以数字开头")
Alternatively, you can also use regular expressions to determine if a string starts with a number. For example:
import re
s = "123abc"
if re.match("^\d", s):
print("字符串以数字开头")
else:
print("字符串不以数字开头")