如何用Python编写将句子中的某个字母进行大小写变换?
发布网友
发布时间:2022-04-24 17:03
我来回答
共2个回答
热心网友
时间:2022-04-18 04:08
# 如何用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
热心网友
时间:2022-04-18 05:26
s.upper()