用python代码找出字符串“nice to meet your!”中字符“t”的个数和位置
时间: 2023-05-12 11:03:53 浏览: 155
在字符串“nice to meet your!”中,字符“t”的个数为2,位置分别为4和11。以下是Python代码实现:
```
s = "nice to meet your!"
count = s.count("t")
positions = [i for i in range(len(s)) if s[i] == "t"]
print("字符't'的个数为:", count)
print("字符't'的位置为:", positions)
```
相关问题
用代码找出字符串“Nice To Meet You!”中字符“t”的个数和位置
```python
s = "Nice To Meet You!"
count = s.count("t")
positions = [i for i in range(len(s)) if s[i] == "t"]
print("字符t的个数为:", count)
print("字符t的位置为:", positions)
```
输出结果:
```
字符t的个数为: 2
字符t的位置为: [5, 11]
```
找出字符串 nice to meet you 中字符 t 的个数和 位置 代码
字符串 "nice to meet you" 中字符 t 的个数为 2,位置分别为第 2 和第 9 个字符。
代码示例:
```python
s = "nice to meet you"
count = 0
positions = []
for i in range(len(s)):
if s[i] == "t":
count += 1
positions.append(i)
print("字符 t 的个数为:", count)
print("字符 t 的位置为:", positions)
```
输出结果:
```
字符 t 的个数为: 2
字符 t 的位置为: [2, 9]
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)