Python 我得到了';无';在我运行的每个打印语句末尾打印。我不完全清楚为什么?
调用函数时,不要添加打印。只需调用函数即可Python 我得到了';无';在我运行的每个打印语句末尾打印。我不完全清楚为什么?,python,Python,调用函数时,不要添加打印。只需调用函数即可 def finished_projects(unfinished_projects, completed_projects): while unfinished_projects: current_project = unfinished_projects.pop() print('completing project: ' + current_project) completed_project
def finished_projects(unfinished_projects, completed_projects):
while unfinished_projects:
current_project = unfinished_projects.pop()
print('completing project: ' + current_project)
completed_projects.append(current_project)
def show_completed_projects(completed_projects):
print('\nThese projects have been completed:')
for project in completed_projects:
print(project)
unfinished_projects = ['pie-chart', 'bar graph', 'line chart']
completed_projects = []
print(finished_projects(unfinished_projects,completed_projects))
print(show_completed_projects(completed_projects))
如果您返回了一些内容,则可以使用“打印”。这是因为您试图打印两个函数的返回值,而这两个函数都没有,请尝试执行以下操作:
def finished_projects(unfinished_projects, completed_projects):
while unfinished_projects:
current_project = unfinished_projects.pop()
print('completing project: ' + current_project)
completed_projects.append(current_project)
def show_completed_projects(completed_projects):
print('\nThese projects have been completed:')
for project in completed_projects:
print(project)
unfinished_projects = ['pie-chart', 'bar graph', 'line chart']
completed_projects = []
finished_projects(unfinished_projects,completed_projects)
show_completed_projects(completed_projects)
因为这两个函数都没有返回任何内容。您正在从函数内部打印。您的函数返回
None
,因此当您调用时,例如,print(show_completed_projects(…)
打印的是返回值None
。
finished_projects(unfinished_projects,completed_projects)
show_completed_projects(completed_projects)