简体   繁体   English

无论如何要在函数内部创建 if 语句?

[英]Is there anyway to create if statement inside function?

Is there anyway to work this main function ?反正有这个主要功能吗?

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)

What should I do to work this in both cases with main function在这两种情况下,我应该怎么做才能使用 main 函数

What exactly is your goal?你的目标究竟是什么?

This is a working example:这是一个工作示例:

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()

This will return test1 = 'test1', test2 = 'test2', test3 = '', test4 = ''这将返回test1 = 'test1', test2 = 'test2', test3 = '', test4 = ''

Without any further details this might not be what you're looking for.如果没有任何进一步的细节,这可能不是你要找的。 Please provide more details for a suitable answer.请提供更多详细信息以获得合适的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM