在 python 课程中解决这个问题,但我终生无法弄清楚为什么这行不通。我宁愿它给我一个错误也不愿打印 0!
问题给了我显示的字符串的变量x,需要打印第一次y使用的索引。
x = 'Poisson geometry plays an important role in noncommutative geometry.'
y = 'u'
i = 0
while i == 0:
for o in x:
if o == y:
print(y, "is first seen in index = ", y.index(o))
i += 1
显示的代码返回:
u is first seen in index = 0
心有法竹
慕桂英546537
FFIVE
相关分类