我正在尝试调用一个函数,该函数将清空我作为参数发送的两个列表。我如何着手清空函数内的列表,并确保一旦代码开始在 Python 的原始函数中重用它们,它们就为空?下面是我用作大型系统测试运行的代码。
def Input():
nextRound = ['Dad', 'Mom']
maleNames = ['son', 'James', 'Mick', 'Dad']
a = int(input('Enter a number please'))
if a == 1:
ErrorInput(1, nextRound, maleNames )
# I want the below to print two empty strings
print(nextRound, maleNames)
def ErrorInput(error, namelist, round):
if error == 1:
print('ERROR: You have entered a number above what is impossible to
score')
namelist = []
round = []
elif error == 2:
print('ERROR: You Have entered a score meaning both players win')
namelist = []
round = []
elif error == 3:
print('ERROR: You have entered a score meaning neither of the two
players win')
namelist = []
round = []
elif error == 4:
print('EEROR: You have entered a negative number, this is
impossible')
namelist = []
round = []
return(namelist, round)
Input()
原文由 Ethan Venencia 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用
namelist.clear()
清除列表