如何用Python编写将句子中的某个字母进行大小写变换?

如题所述

# 如何用Python编写将句子中的某个字母进行大小写变换?
# sentence = 'i am iran man'
# word = 'i'
# 结果 upper_lower_word('i am iran man','i') => I am iran man

def upper_lower_word(sentence, word, is_upper = True):
index = sentence.find(word)
if index != -1:
if is_upper == True:
res_word = word.upper()
else:
res_word = word.lower()
res = sentence[0:index] + res_word + sentence[index+1:]
return res
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-04-01
s.upper()
相似回答