Python – check if string starts with number

With the help of isdigit() function we can check if a string start with number or not.

Lets check with following examples:

>>> input = '1viewsby'
>>> input[0].isdigit()
True

Above example is returned true since input string is started with with number.

>>> input = 'viewsby'
>>> input[0].isdigit()
False

Since input is is not started with number above example returned false.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s