输入若干字符串输出其中含有字符k的字符串python
时间: 2023-12-20 15:08:00 浏览: 84
![PPTX](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PPTX.png)
第4章 字符串.pptx
好的,可以使用Python语言编写一个程序来实现该功能,代码如下:
```python
strings = ["hello", "world", "kitty", "python", "programming"]
k_strings = []
for s in strings:
if "k" in s:
k_strings.append(s)
print(k_strings)
```
程序首先定义了一个包含多个字符串的列表 `strings`,然后创建了一个空列表 `k_strings`,用于存储含有字符"k"的字符串。接下来,程序使用 `for` 循环遍历 `strings` 列表中的每一个字符串,并使用 `if` 语句判断该字符串中是否含有字符"k"。如果含有,就将其添加到 `k_strings` 列表中。最后,程序输出 `k_strings` 列表的内容,即所有含有字符"k"的字符串。
你可以将需要处理的字符串列表赋值给 `strings` 变量,然后运行该程序即可得到结果。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)