I want to create a function that would check if first letter of string is in uppercase. This is what I've came up with so far:
def is_lowercase(word):
if word[0] in range string.ascii_lowercase:
return True
else:
return False
When I try to run it I get this error:
if word[0] in range string.ascii_lowercase
^
SyntaxError: invalid syntax
Can someone have a look and advise what I'm doing wrong?
Character. isUpperCase(char ch) determines if the specified character is an uppercase character. A character is uppercase if its general category type, provided by Character.
C++ isupper() The isupper() function in C++ checks if the given character is a uppercase character or not.
In Python, isupper() is a built-in method used for string handling. This method returns True if all characters in the string are uppercase, otherwise, returns “False”.
isupper() – check whether a character is uppercase.
Why not use str.isupper()
;
In [2]: word = 'asdf'
In [3]: word[0].isupper()
Out[3]: False
In [4]: word = 'Asdf'
In [5]: word[0].isupper()
Out[5]: True
This is built-in for strings:
word = "Hello"
word.istitle() # True
but note that str.istitle
looks whether every word in the string is title-cased, so this might give you a surprise:
"Hello world".istitle() # returns False!
If you just want to check the very first character of a string use this:
word = "Hello world"
word[0].isupper() # True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With