如何让一个字符串中的第二个字母大写,其他字母都小写。例如input是“Lady and the Gentle”, output是"lAdy aNd tHe gEntle"
如何让一个字符串中的第二个字母大写,其他字母都小写。例如input是“Lady and the Gentle”, output是"lAdy aNd tHe gEntle"
收起
你例子显示的是每个单词的第二个字符大小,其它小写
而你问话中则感觉是一个句子字符串中第二个字符大写,其它小写,这是不同的。
s = 'Lady and the Gentle'
s = s.lower()
lst = s.split(" ")
for i in range(len(lst)):
if (len(lst[i])>=2):
line=lst[i]
t=line[0]+line[1].upper()+line[2:]
lst[i]=t
s =" ".join((lst))
print(s)
报告相同问题?