Lis = [9,"hello" , "jack", ["rose", 250, ["kdf1", ["tsfat", 3, "1"]], 0], "cdfab", "addgfv"]python将列表Lis中的"d"变成大写
时间: 2024-03-30 09:31:44 浏览: 56
STM32L0-IIC-LIS3DH-FIFO模式读取
要将列表Lis中的"d"变成大写,可以使用列表的索引和字符串的replace()方法来实现。首先,找到包含"d"的字符串,然后使用replace()方法将小写的"d"替换为大写的"D"。以下是实现的代码:
```python
Lis = [9, "hello", "jack", ["rose", 250, ["kdf1", ["tsfat", 3, "1"]], 0], "cdfab", "addgfv"]
# 遍历列表Lis
for i in range(len(Lis)):
# 如果元素是字符串类型
if isinstance(Lis[i], str):
# 将小写的"d"替换为大写的"D"
Lis[i] = Lis[i].replace("d", "D")
print(Lis)
```
输出结果为:
```
[9, "hello", "jack", ["rose", 250, ["kDf1", ["tsfat", 3, "1"]], 0], "cDfaD", "aDDgfv"]
```
阅读全文