-1
无法理解,而不是为什么这个函数返回None
filename
为什么递归没有返回值
import os
def existence_of_file():
filename = str(input("Give me the name: "))
if os.path.exists(filename):
print("This file is already exists")
existence_of_file()
else:
print(filename)
return filename
a = existence_of_file()
print(a)
输出:
Give me the name: app.py
This file is already exists
Give me the name: 3.txt
3.txt
None
这是不应该使用递归。这应该只是在一个循环中完成。 – FamousJameous
您没有返回递归调用的结果。 –