如何在Python中打印方法的返回值? [英] How to print return value of method in Python?
本文介绍了如何在Python中打印方法的返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Queue():
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def Enqueue(self,item):
return self.items.insert(0, item)
def Size(self):
return len(self.items)
def Dequeue(self):
return self.items.pop()
Q = Queue()
def Hotpot(namelist,num):
for name in namelist:
Q.Enqueue(name)
while Q.Size() > 1:
for i in range(num):
Q.Enqueue(Q.Dequeue())
Q.Dequeue()
return Q.Dequeue() # I would like to print and see what is getting removed, I tried with x = Q.Dequeue(), print x and print Q.Dequeue() but im getting "None"
print Hotpot(['A','B','C','D','E','F'],7)
Hi Team,
我正在尝试检查Queue的代码,这里我想打印哪个值正在删除每个循环。虽然打印我没有任何东西,但请帮助我为我的期望做些什么改变。
Hi Team, I am trying above code for checking Queue, here I would like to print which value is removing each cycle. While printing I am getting none oly, please help me what changes I have to do for my expectation.
推荐答案
如果你想要知道要返回什么,你需要在本地保存,打印你保存的内容,然后返回你保存的内容。类似于:
If you want to know what's goingto be returned, you need to save it locally, print what you saved, then return what you saved. Something like:
x = Q.Dequeue()
print(x)
return x
这篇关于如何在Python中打印方法的返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文