This code doesn’t work – is there another way I can add a key-value pair with a variable as the value?
BTC_ = {"Name": "BTC", "liq": 57000}
ETH_ = {"Name": "ETH", "liq": 50000}
BTC = BTC_['liq']
ETH = ETH_['liq']
ETHp = ETH / 50000
BTCp = BTC / 50000
BTC_.update['price': BTCp ]
ETH_.update['price': ETHp ]
This code currently gives the error:
Output: builtin_function_or_method object is not subscriptable
>Solution :
You call functions with (arguments) after the function name, not [arguments]. And the argument to dict.update() must be a dictionary. So the correct syntax would be:
BTC_.update({'price': BTCp})
But if you’re just setting one element, this is normally done using assignment:
BTC_['price'] = BTCp
.update() is used when you want to set multiple elements by merging with another dictionary.