#string indexing
import random
word = "index"
print "The word is:" , word, "\n"
high = len(word)
low = -len(word)
for i in range(10):
position = random.randrange(low,high)
print "word[", position, "]\t", word[position]
raw_input("\n\nPress the enter key to exit,")
我从一本名为“Python编程指南”的书中复制了这本书。我不知道为什么我们必须在
中添加两个逗号[", position, "]
这是什么意思?当我删除这两个逗号时,为什么会出错?
答案 0 :(得分:0)
在python3中
print("word[", position, "]\t", word[position])
"字[",位置," [\ t",字[position]是print()的参数