Here are my βanswersβ ββ(trying to be unique here, I really don't recommend for this particular case :-)
Using ord () and special form a <= b <= c :
//starts_with_digit = ord('0') <= ord(mystring[0]) <= ord('9') //I was thinking too much in C. Strings are perfectly comparable. starts_with_digit = '0' <= mystring[0] <= '9'
(This a <= b <= c , like a < b < c , is a special Python construct, and it's pretty neat: compare 1 < 2 < 3 (true) and 1 < 3 < 2 (false) and (1 < 3) < 2 (true). This isn 'how it works in most other languages.)
Using regex :
import re //starts_with_digit = re.match(r"^\d", mystring) is not None //re.match is already anchored starts_with_digit = re.match(r"\d", mystring) is not None
user166390 Apr 7 2018-11-11T00: 00Z
source share