如何在python中为if/else语句的函数赋值特定的返回变量[已关闭]

tquggr8v  于 2022-12-21  发布在  Python
关注(0)|答案(3)|浏览(191)

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
昨天关门了。
Improve this question
我有以下两个职能:

def abc():
    i = "False"
    j = "100"
    return i,j

def xyz():
    if abc() == "False":  #I want to compare "False" with variable "i"
       print("Not Done")
    else:
        abc() == "101"    ##I want to compare "False" with variable "j"
        print("something else:")
xyz()

电流输出:

something else:

预期输出:

Not Done

我想知道如何检查特定return变量的特定if/else语句。

pod7payv

pod7payv1#

就这么简单?

def xyz():
    i, j = abc()
    if i == "False":
        print("Not Done")
    elif j == "101":
        print("something else:")
mkh04yzy

mkh04yzy2#

如果希望代码正常工作,因为函数返回的是元组:

def abc():
    i = "False"
    j = "100"
    return i,j

def xyz():
    if abc()[0] == "False":  #I want to compare "False" with variable "i" #[0] for i
       print("Not Done")
    else:
        abc()[1] == "101"    ##I want to compare "False" with variable "j" #[1] for j
        print("something else:")
kyvafyod

kyvafyod3#

我猜如果abc()函数中的任何变量为“False”,您可能希望打印not done。在这种情况下,答案如下:

def abc():
i = "False"
j = "100"
return i,j
m,n=abc()
def xyz():
    if m or n == "False":  #I want to compare "False" with variable "i"
       print("Not Done")
    else:
                                    ##I want to compare "False" with variable "j"
        print("something else:")
xyz()

相关问题