编程很新.
想知道为什么这个例子打印列表中的所有项目,而第二个例子只打印第一个?
def list_function(x):
for y in x:
print y
n = [4, 5, 7]
list_function(n)
Run Code Online (Sandbox Code Playgroud)
def list_function(x):
for y in x:
return y
n = [4, 5, 7]
print list_function(n)
Run Code Online (Sandbox Code Playgroud) 为什么这会打印出列表[None, None, None]而不是列出我输入的三个答案?
options = []
for i in range(3):
options[i] = options.append(raw_input("enter an option"))
print options
Run Code Online (Sandbox Code Playgroud) 我目前正在查看财务 API 的一些代码,并且有一个示例函数似乎可以处理指定类型的请求(我对请求很陌生,所以仍在学习这个)。
我不明白函数 return 中的语法。我从来没有见过这样的方法前面的字典,这里发生了什么?感谢您的建议。
import requests
def dispatch_request(http_method):
session = requests.Session()
session.headers.update({
'Content-Type': 'application/json;charset=utf-8',
'X-MBX-APIKEY': KEY
})
return {
'GET': session.get,
'DELETE': session.delete,
'PUT': session.put,
'POST': session.post,
}.get(http_method, 'GET')
Run Code Online (Sandbox Code Playgroud)
如果有人对完整示例感兴趣,可以在此处查看:https : //github.com/binance-exchange/binance-signature-examples/blob/master/python/spot.py