Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.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 函数中是否有创建if语句的方法?_Python_Parameters_Arguments - Fatal编程技术网

Python 函数中是否有创建if语句的方法?

Python 函数中是否有创建if语句的方法?,python,parameters,arguments,Python,Parameters,Arguments,是否有任何方法可以使用此主要功能 def foo(test1,test2,test3,test4): if something = True: test1 = test1 + 10 test2 = test2 + 20 else: test3 = test3 + 30 test4 = test4 + 25 def main(): foo(test1,test2,test3,test4) 在这两种情况下,

是否有任何方法可以使用此主要功能

def foo(test1,test2,test3,test4):
    if something = True:
        test1 = test1 + 10
        test2 = test2 + 20
    else:
        test3 = test3 + 30
        test4 = test4 + 25


def main():
    foo(test1,test2,test3,test4)

在这两种情况下,我应该如何使用main函数来实现这一点?您的目标是什么

这是一个工作示例:

def foo(test1,test2,test3,test4,something):
    if something == True: # or simply if something:
        test1 = 'test1'
        test2 = 'test2'
    else:
        test3 = 'test1'
        test4 = 'test2'

    return test1,test2,test3,test4

def main():
    something = True
    test1,test2,test3,test4 = '','','',''
    test1,test2,test3,test4 = foo(test1,test2,test3,test4,something)
    print(test1,test2,test3,test4 )

if __name__ == "__main__":
    main()
这将返回
test1='test1',test2='test2',test3='',test4=''


如果没有任何进一步的细节,这可能不是你想要的。请提供更多详细信息以获得合适的答案。

如果某物==True:
或只是
如果某物:
您好,您应该在问题中提供更多详细信息。但重要的是,这是Python的基础,因此您应该在创建主题之前进行搜索。如果您面临任何问题,您能否告诉我们更多关于此代码的最终目标和问题。也许您想对上述问题进行评论?是的。我错过了真正可以表达我思想的地方。