首页 > 解决方案 > Python简单拆分器

问题描述

我试图数数,直到它找到一个“@”符号,然后数数它需要多少个字母才能找到,这样我就可以使用我尝试了这个简单的代码,但似乎找不到我期待的问题@ 6在这种情况下,但它根本没有输出

email = "email@gmail.com"
length = len(email)
count = 0
counter = email[count]
counter
for i in range(length):
    if counter == "@":
        print(counter)
        print(count)
        i  = 0
    else:
        count = count + 1

标签: pythonpython-3.x

解决方案


如果您只想要 @ 所在的字符串索引,为什么不使用 string.index()

>>> email = "email@gmail.com"
>>> email.index('@')
5

推荐阅读