如何在python中更改字符串中最后一个字母的大小写?

Hay*_*aas 1 python string lowercase

所以我想将字符串中的最后一个字符更改为小写.下面的代码是我用来向后打印字符串的方法,但是list将最后一个字符留作首都,我无法弄清楚如何解决这个问题!

        if s[-1] == "x":
            new = ""
            last_index = len(s)-1
            for i in range(last_index, -1, -1):
                new += s[i]
            s = new
            s = "".join(word[0].upper() + word[1:] for word in s.split())
        print (s)
Run Code Online (Sandbox Code Playgroud)

例如:输入是:

Inbox
Run Code Online (Sandbox Code Playgroud)

这个输出:

XobnI
Run Code Online (Sandbox Code Playgroud)

但我希望它输出:

Xobni
Run Code Online (Sandbox Code Playgroud)

提前致谢!

Ash*_*ary 7

用途str.title:

>>> "Inbox"[::-1].title()
'Xobni'
Run Code Online (Sandbox Code Playgroud)