5

So I am writing a function that takes in a string input (ex: abcdefg) and a shorter portion of that input (ex: cde) and searches for it within the first longer string.

How do I make it so that only that second portion is capitalized in the first string?

Ex:

  • Input 1: abcdefg
  • Input 2: cde
  • abCDEfg
1
  • 5
    have you tried something? Commented Jul 22, 2013 at 18:01

2 Answers 2

20
def foo(str1, str2): return str1.replace(str2, str2.upper()) 
Sign up to request clarification or add additional context in comments.

Comments

6
>>> a = "abcdefg" >>> b = "cde" >>> c = b.upper() >>> a.replace(b,c) 'abCDEfg' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.