I have a string that starts with a number (from 0-9) I know I can "or" 10 test cases using startswith() but there is probably a neater solution
so instead of writing
if (string.startswith('0') || string.startswith('2') ||
string.startswith('3') || string.startswith('4') ||
string.startswith('5') || string.startswith('6') ||
string.startswith('7') || string.startswith('8') ||
string.startswith('9')):
#do something
Is there a cleverer/more efficient way?
Python's string
library has isdigit()
method:
string[0].isdigit()