- print:輸出某種資料類型
- placeholder:先佔位子放東西的地方
- 用大括弧 { } 來表示
print("revenue in{}".format(year)) #兩個變動用,隔開,放兩個大括弧{} print("revenue in{} was{}".format(year,revenue))
- 用大括弧 { } 來表示
- format:
- 可以把東西放到placeholder佔位子的地方
- 用途:希望某些輸出的資料會變動,例如不同的年
.format(year)
PRACTICE OPPORTUNITY
Write a Python code that performs the following tasks:
- 1. Prints out the following message to the screen:
"Procter and Gamble (P&G), which reports using US GAAP, sold a piece of land for $500000"
- 2. Generalize your code to the company name, reporting standard, and dollar amount
- 3. Test your code and perform a sanity check
print("Procter and Gamble (P&G), which reports using US GAAP, sold a piece of land for $500000" )
company_name = "Procter and Gamble (P&G)"
reporting_stanard = "US GAAP"
dollar_amount = "$5000000"
print("{}, which reports using {}, sold a piece of land for {}".format(company_name,reporting_stanard,dollar_amount))
你好,我是蔡至誠PG,任職於《阿爾發證券投顧》,《我畢業五年,用ETF賺到400萬》作者,《提早五年退休:PG 財經個人財務調配術》講師。