'how can i add .capitalize in this code to capitalize only the first word of my reversed string

def reverse(s):
    if Len(s) == 0:
        return s
    else:
        return reverse(s[1:]) + s[0]

s = ""

print("the string : ",end="")
print(s)
print("reversed string: ",end="")
print(reverse(s))


Solution 1:[1]

Call capitalize on the string that's returned by reverse:

>>> reverse("The quick brown fox")
'xof nworb kciuq ehT'
>>> reverse("The quick brown fox").capitalize()
'Xof nworb kciuq eht'

No need to split it out by word since the first letter of the string will necessarily be part of the first word also.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samwise