Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我得到了';无';在我运行的每个打印语句末尾打印。我不完全清楚为什么?_Python - Fatal编程技术网

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)