96.2k views
4 votes
A function that turns only the first two letters uppercase

User OOEric
by
7.5k points

1 Answer

3 votes

A function that turns only the first two letters uppercase using python built-in capitalize() method with string indexing:

def first_two_uppercase(text):

"""

This function takes a string and returns a new string with the first two letters

uppercase and the rest of the string lowercase.

Args:

text: The string to be modified.

Returns:

A new string with the first two letters uppercase and the rest lowercase.

"""

return text[:2].upper() + text[2:].lower()

User Guymage
by
8.3k points