在python里 现有两个字符串“hasdhsdshedi”和“hfgddhsddshfs”,利用Python实现一个函数,函数功能为打印出两个字符串中对应位置相同的字母
时间: 2023-05-28 12:01:49 浏览: 84
可以使用zip函数将两个字符串打包成元组,然后利用for循环遍历比较每个字母是否相同,相同则打印出来。
代码示例:
```python
def print_common_letters(s1, s2):
for i, j in zip(s1, s2):
if i == j:
print(i)
s1 = "hasdhsdshedi"
s2 = "hfgddhsddshfs"
print_common_letters(s1, s2) # 输出:h d d s d s h
```
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)