나는 인자로 보내는 두 개의 목록을 비우는 함수를 호출하려고한다. 함수 내에서리스트를 비우고 코드가 파이썬의 원래 함수에서 재사용되면 비어 있는지 확인하는 방법은 무엇입니까? 아래는 큰 시스템에 대한 테스트 실행으로 사용하고있는 코드입니다.파이썬에서 빈 목록을 반환하는 방법
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()
코드가 사용자 질문과 어떤 관련이 있는지 따라야합니다. 나는 또한 왜이 일을하는지 이해하지 못한다. 분명히 할 수 있니? –
둘 중 어느 하나도 이해할 수 없지만 줄을 'nextRound, maleNames = ErrorInput (1, nextRound, maleNames)'로 바꾸면 업데이트 할 수 있습니다. –
이해가 안됩니다. 'aList = []''aList'라는리스트를 '비우는'것이 아닙니까? – Nae