高清轉換(字符串翻譯):轉換字到其它字保持原來的格式
'''
>>> translations = {'he':'she', 'brother':'sister'}
>>> translate('he', translations)
'she'
>>> translate('HE', translations)
'SHE'
>>> translate('He', translations)
'She'
>>> translate('brother', translations)
'sister'
>>> translate('my', translations)
'my'
'''
我有這樣的投入。我用translations.get(字符串)讓他和妹妹,它運作良好。但事情是我不能將字符串轉換爲'她'或'他'(原始格式)。 如何在Python中做到這一點?
你可以用'str.lower ()'/'str.title()'按照要求 – ksai