python function capitalize first letter only
Question: I need build a function to transform 1st character only, from any word but
also this function need address the problem if the 1st character from the word
doesn't starts with a character, for example '_sun',' -tree', '2cat' these
words need be like _Sun, -Tree, 2Cat. This is what I have so far, it can
convert any word but I don't know how do 2nd part, need use ASCII?? to get
value of 1st character and see if the word starts with character?

    
    
    def convert(capital):
        return capital[0].upper() + capital[1:]
    
    def main():
       print(convert('sun'))
    
    main()
    


Answer: One option is to use a regex and limit it to 1 replacement, eg:

    
    
    >>> import re
    >>> re.sub('[a-zA-Z]', lambda m: m.group().upper(), '2cat', 1)
    '2Cat'
    >>> re.sub('[a-zA-Z]', lambda m: m.group().upper(), 'sun', 1)
    'Sun'
    

