简体   繁体   English

Python 如果不等于几个条件

[英]Python If not equal several conditions

My aim is to retrieve API from Coinmarketcap and find the sum of market cap without stablecoins.我的目标是从 Coinmarketcap 中检索 API 并找到没有稳定币的市值总和。

I use Python and basic loop with if-else.我使用 Python 和带有 if-else 的基本循环。 The problem is that I have to check this condition of let's say 500 coins against the set of stablecoins such as "USDT", "USDC", "BUSD".问题是我必须检查这个条件,比方说 500 个硬币与一组稳定币,如“USDT”、“USDC”、“BUSD”。

Below is my attempt for just one condition, but I also need to sum up market cap if they're not USDC and BUSD and other stablecoins.下面是我对一种情况的尝试,但如果它们不是 USDC 和 BUSD 以及其他稳定币,我还需要总结市值。

for item in data["data"]:
    crypto_cap = item["quote"]["USD"]["market_cap"]
    crypto_symbol = item["symbol"]
    if crypto_symbol != "USDT":
        cap_sum += crypto_cap
print(market_cap)

You might use not in check against list in this case as follows, replace在这种情况下,您可能会使用not in check against list,替换

if crypto_symbol != "USDT":

using使用

if crypto_symbol not in ["USDT", "USDC", "BUSD"]:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM