⊗pyPmIBSCh 183 of 208 menu

Checking a String in Python

istitle isupper islower isalpha isalnum isdigit isnumeric isspace

Given a string:

txt = 'Abcde'

Make sure it starts with a capital letter.

Given a list:

lst = ['User1', 'User2', 'user3', 'User4']

Check if each of its elements starts with a capital letter.

Given a string:

txt = 'ABCDE'

Make sure all of its letters are uppercase.

Given a string:

txt = 'abcde'

Make sure all of its letters are lowercase.

Given a string:

txt = 'abcde'

Check that it consists only of letters.

Given a string:

txt = '12345'

Check that it consists only of numbers.

Given a string:

txt = 'Ⅷ'

Check that it consists only of numbers.

Given a string:

txt = '12345abc'

Make sure it only contains letters and numbers.

Given a string:

txt = 'a1b2c3d '

Make sure it only contains letters and numbers.

Given a string:

txt = ' '

Check if it consists only of spaces.

Given a list:

lst = ['a', 'b', ' ', 'c', '']

Check if it contains elements that contain only spaces.

byenru