小编Dud*_*ude的帖子

返回vs打印列表

编程很新.
想知道为什么这个例子打印列表中的所有项目,而第二个例子只打印第一个?

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)

python printing return list

5
推荐指数
1
解决办法
549
查看次数

从原始输入附加到列表

为什么这会打印出列表[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)

python

1
推荐指数
1
解决办法
76
查看次数

在 Python 中以请求 get() 方法为前缀的字典

我目前正在查看财务 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

python session dictionary get python-requests

1
推荐指数
1
解决办法
49
查看次数

标签 统计

python ×3

dictionary ×1

get ×1

list ×1

printing ×1

python-requests ×1

return ×1

session ×1