A. 基本情况 但是,检查职能是否恢复某些价值的最佳方式是什么?
def hillupillu():
a= None
b="lillestalle"
return a,b
if i and j in hillupillu(): #how can i check if i or j are empty? this is not doing it of course;-P
print i,j
A. 基本情况 但是,检查职能是否恢复某些价值的最佳方式是什么?
def hillupillu():
a= None
b="lillestalle"
return a,b
if i and j in hillupillu(): #how can i check if i or j are empty? this is not doing it of course;-P
print i,j
如果你意味着你可以预测某些职能的回报价值的数量,那么,
i, j = hillupillu()
如果该功能确实有两个价值,则将产生<代码>ValueError。 您可以按照通常的<条码>、条码>收集。 构造:
try:
i, j = hillupillu()
except ValueError:
print("Hey, I was expecting two values!")
This follows the common Python idiom of "asking for forgiveness, not permission". If hillupillu
might raise a ValueError
itself, you ll want to do an explicit check:
r = hillupillu()
if len(r) != 2: # maybe check whether it s a tuple as well with isinstance(r, tuple)
print("Hey, I was expecting two values!")
i, j = r
If you meant that you want to check for None
in the returned values, then check for None in (i, j)
in an if
-clause.
如果你不了解图中有多少价值,你可以检查其长度:
tuple_ = hillupillu()
i = tuple_[0] if tuple_ else None
j = tuple_[1] if len(tuple_) > 1 else None
在从职能中获得价值后:
i, j = hillupillu()
您可核实价值是否为None
和is
的操作者:
if i is None: ...
你们也可以只是检验真相价值的价值:
if i: ...
if(i == "" or j == ""):
//execute code
象这样说,但如果你给它一个<代码>的话。 页: 1
if(i == None or j == None):
//execute code
希望
您可以核实该职能的回报价值是否为:
r_value = foo(False)
x, y = None, None
if type(r_value) == tuple:
x, y = r_value
else:
x = r_value
print(x, y)
举例来说,如果已知该功能可以收回一个精确的长度2的图形(例如,采用<代码>return a, b),或一个单一的数值,则该功能就属于这种情况。 它可以扩大到处理其他职能可以退还其他期限的拖.的情况。
我不认为“Foo”的接受答案是正确的,原因有几个:
try
block, and so we can only deal with them inside that block.Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...
I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...
Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...
Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...
I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...
Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...
Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...
I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...