Convert UPPERCASE string to sentence case in Python
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How does one convert an uppercase string to proper sentence-case? Example string: "OPERATOR FAIL TO PROPERLY REMOVE SOLID WASTE" Using titlecase(str) gives me: "Operator Fail to Properly Remove Solid Waste" What I need is: "Operator fail to properly remove solid waste" Is there an easy way to do this? 回答1: Let's use an even more appropriate function for this: string.capitalize >>> s="OPERATOR FAIL TO PROPERLY REMOVE SOLID WASTE" >>> s.capitalize() 'Operator fail to properly remove solid waste' 回答2: This will work for any sentence, or any