#!/usr/bin/python
def split(x):
return [char for char in x]
def func(x):
a = []
a.append(split(x))
for i in a:
if a[i]== "\"":
print ("hw")
str = "string\""
print (str)
func(str)
def split(x):
return [char for char in x]
def func(x):
a = split(x) # notice this line
for i in range(len(a)):
if a[i]== "\"":
print ("hw")
str1 = "string\""
print (str1)
func(str1)
我修改了您的代码,请尝试下面的代码:
@See this Ouput Demo
或:
或:
更新
其实比你想象的简单多了。首先
split
是一个内置函数。其次,for i in a
检查字符串的每个字符a
您不需要索引。请尝试以下操作:如果还需要获取找到的字符的索引,可以执行以下操作:
相关问题 更多 >
编程相关推荐