有人可以向我解释为什么在下面使用“print”会继续重新运行代码,但使用“return”将只运行一次?你将如何使用“返回”而不是“打印”来重新运行自己的代码?打印vs带time.sleep的python返回
感谢雅“LL!
def stop():
while True:
oanda = oandapy.API(environment="practice", access_token="xxxxxxxx")
response = oanda.get_prices(instruments="EUR_USD")
prices = response.get("prices")
asking_price = prices[0].get("ask")
s = asking_price - .001
print s
time.sleep(heartbeat)
print stop()
VS
def stop():
while True:
oanda = oandapy.API(environment="practice", access_token="xxxxxxxxxx")
response = oanda.get_prices(instruments="EUR_USD")
prices = response.get("prices")
asking_price = prices[0].get("ask")
s = asking_price - .001
return s
time.sleep(heartbeat)
print stop()
如果while循环,除非使用'break'声明 – logic