如何在python中将一个字符串复制到另一个字符串

2024-09-30 20:37:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个字符串,s1s2,我需要找出这两个字符串中是否有共同的字母,并使其加倍,例如:

s1 = "Hello World"
s2 = "lo"
output = "Helllloo Woorlld"

我的代码:

^{pr2}$

我得到一个错误:

    if d[s2[w]]:
IndexError: string index out of range 

Tags: 字符串代码helloloworldoutputif错误