如何打印文字对应的索引

用python编写一个简单的小程序:将文字对应的索引打印出来。

test=input('>>>')
print(test)
l=len(test)
print(l)
r=range(l)
for item in r:
    print(item,test[item])

以上为了练习步骤繁琐,下面程序比较简单。

test=input('>>>')
for item in range(len(test)):
    print(item,test[item])

其实两个程序功能原理完全一样,但是对于新手来说,第二个明显难读一点,所以说读程序是明白缘由逐步进行。

猜你喜欢

转载自www.cnblogs.com/lixuejian/p/9615169.html