I am trying to get text via the return function to concat into a multiline string such as shown below.
btc_positions=[{
'symbol: BTC',
'margin_balance: 0.15',
'margin_position: 0.05',
'margin_frozen: 0.01'}]
for pos in btc_positions:
for attributes in pos:
text = f"{attributes}: {pos[attributes]}"
return text
text is in this format (symbol: BTC) but throws the error 'return' outside function.
Console Error: python shitcoin_alerts.py File "shitcoin_alerts.py", line 34 return text ^ SyntaxError: 'return' outside function. Fixed! (Return has to be used inside a function)
My intention is to return text to create the multiline string below. But can't seem to find any ways I can do it.
multiline_text = f'''
symbol={symbol},
margin_balance: {margin_balance},
margin_position:{margin_position},
margin_frozen: {margin_frozen}
'''
Expected output from this multiline string will be:
-----------------------
symbol=BTC,
margin_balance=0.15,
margin_position=0.05,
margin_available=0.01
----------------------
returnis to return from a function, but you are not in one.set:{'symbol: BTC', 'margin_balance: 0.15', 'margin_position: 0.05', 'margin_frozen: 0.01'}. Did you want adict:{'symbol': 'BTC', 'margin_balance': '0.15', 'margin_position': '0.05', 'margin_frozen': '0.01'}?multiline_text. I'll have to change my answer.