所以我喜歡從我的函式輸入中生成變數
所以基本上,if 陳述句應該檢查變數是否為真。我想使用函式輸入 “-結果”來檢查。
Function-outcome = True
Function2-outcome = False
c
def a(B):
Global c
If f’{B}-outcome’ == True:
Print(”yes”)
Else:
Print(”no”)
a(”function”)
a(”function2”)
這是一個例子,讓你更好地理解我的問題!
我試圖找到解決方案,但在任何地方都找不到
謝謝!
uj5u.com熱心網友回復:
import yfinance as yf
from datetime import date
import pandas as pd
d_start = '2022-01-01'
d_end = date.today().strftime('%Y-%m-%d')
#top50 S&P to create a list, if you will use a variable from an API you will just need to declare it as a string
#you can create a list of your fav ones and it will work the same, I grabbed from this site because it was the top 50 easy to get
tl = pd.read_html('https://dailypik.com/top-50-companies-sp-500/')[0]['Symbol'].to_list()
def main(l, d_start, d_end):
#I used the download function here, you will use the one that will fulfill your aim, analysis, actions, balance_sheet
#for isntance df = yf.earnings
df = yf.download(str(l), start=d_start, end=d_end)
#you can't assign a variable with a fstring, the work around is name the df opening opportunities later on
df.name = l
return df
df_list = [main(k, d_start, d_end) for k in tl]
di_ticks = {k:v for k,v in zip([df_list[i].name for i in range(0, len(df_list))], df_list)}
#here you can pass any tick that you have in the tl(tick list)
di_ticks['MSFT']

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/533716.html
標籤:Python功能变量f弦
