import random
warrior = 'Warrior'
mage = 'Mage'
warlock = 'Warlock'
paladin = 'Paladin'
firstList = [warrior, mage, warlock, paladin]
print(firstList[0], firstList[1], firstList[2], firstList[3])
firstNumber = random.randint(0, 3)
firstList[firstNumber] = '*taken*'
print(firstList[0], firstList[1], firstList[2], firstList[3])
secondList = [paladin, warlock, mage, warrior]
print(secondList[0], secondList[1], secondList[2], secondList[3])
假设随机数选择 0 我意识到第 9 行实际上只是将列表条目更改为“ taken ”,而不是将条目引用的“warrior”变量更改为“ taken ”。有没有办法做到这一点?
原谅魔兽参考。