使用If条件时Python中出现非类型错误

使用If条件时Python中出现非类型错误,python,function,typeerror,iterable,nonetype,Python,Function,Typeerror,Iterable,Nonetype,我很难让python中的一个函数正常工作。我的函数代码如下: def checkBlackjack(value, pot, player, wager): if (value == 21): print("Congratulations!! Blackjack!!") pot -= wager player += wager print ("The pot value is $", pot) print ("

我很难让python中的一个函数正常工作。我的函数代码如下:

def checkBlackjack(value, pot, player, wager):
    if (value == 21):
        print("Congratulations!! Blackjack!!")
        pot -= wager
        player += wager
        print ("The pot value is $", pot)
        print ("Your remaining balance is $",player)
        return (pot, player)
函数调用是:

potValue, playerBalance = checkBlackjack(playerValue, potValue, playerBalance, wager)
我得到的错误是:

potValue, playerBalance = checkBlackjack(playerValue, potValue, playerBalance, wager)
TypeError: 'NoneType' object is not iterable
由于错误涉及无法迭代,因此我不确定如何将其与使用if条件联系起来


任何帮助都将不胜感激。谢谢

仅当函数中的条件满足时才返回某些内容,否则函数默认返回
None
,然后尝试将
None
解包为两个值(变量)

仅当函数中的条件满足时才返回某些内容,否则,默认情况下,函数返回
None
,然后尝试将
None
解包为两个值(变量)

以下是解决此问题的方法:

>>> a, b = None
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    a, b = None
TypeError: 'NoneType' object is not iterable
>a,b=无
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
a、 b=无
TypeError:“非类型”对象不可编辑
在这一点上,问题应该是清楚的。如果没有,可以在手册中查找多个作业。

以下是解决此问题的方法:

>>> a, b = None
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    a, b = None
TypeError: 'NoneType' object is not iterable
>a,b=无
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
a、 b=无
TypeError:“非类型”对象不可编辑

在这一点上,问题应该是清楚的。如果没有,可以在手册中查找多个作业。

你应该问自己当
不是
21
时会发生什么。你应该问自己当
不是
21
时会发生什么。