How to check if a specific position in a string character or digit or not by using isdigit, isalpha

32 Views Asked by At

I wanna check a specific position in my string if it a character or not using isalpha the same by isdigit

I tried Using startswith and endswith but it didn’t work because I need to check only the start and the end of the string

1

There are 1 best solutions below

0
Spunnring On

You can select the i-th character of your string like this: ith_character = string[i] (starting with zero, of course). So, for example, if you'd like to check whether the third character is a digit, you'd write: string[2].isdigit()