Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
因此,我正在编写一个函数,该函数接受字符串输入(例如:)abcdefg和该输入的较短部分(例如cde:),并在第一个较长的字符串中搜索它。
abcdefg
cde
如何使第一个字符串中只有第二部分大写?
前任:
def foo(str1, str2): return str1.replace(str2, str2.upper())
>>> a = "abcdefg" >>> b = "cde" >>> c = b.upper() >>> a.replace(b,c) 'abCDEfg'