为什么在函数里打印要返回的值和调用函数打印返回值不相等,调用函数打印了个None

db=[
    {'id':1,'name':'唐艺昕','text':'对不起,我不知道,那吻与爱无关','parent':None,'child':[]},
    {'id':2,'name':'迪丽热巴','text':'晚上还来吗?','parent':None,'child':[]},
    {'id':3,'name':'宋轶','text':'想你','parent':None,'child':[]},
    {'id':4,'name':'李孝利','text':'汉语真复杂','parent':1,'child':[]},
    {'id':5,'name':'BlackGirl','text':'曾经迷惘的心神,是你牵引我走出寂寞。','parent':1,'child':[]},
    {'id':6,'name':'alex','text':'???','parent':5,'child':[]},
]
tem_db=db

def position(commenter,**kwargs):
    temp_position=kwargs.get("posi")

    if commenter["parent"]==None:
        print(f"打印的值为{temp_position}")
        return temp_position
    else:
        temp_position+=1
        temp_parent=commenter["parent"]
        for c_commenter in db:
            if c_commenter["id"]==temp_parent:
                temp_commenter=c_commenter

                position(temp_commenter,posi=temp_position)
                break

for i in db:
    print(f"返回的值为{position(i,posi=0)}")
    print("------------")

一个练习题,程序要实现多级评论功能,我想用函数记录缩进值,但是有缩进的对象都返回None

img

问题解决了,23行return就行了

尴尬了,,我竟然没理解你的意思