2017-04-04 63 views
1

而我讀this爲我解決這個代碼與F字符串?

具有此代碼

We can also do that this way: 
We'd have 500000 beans, 500 jars, and 5 crates. 

,當我修改爲打氣498

print ("We can also do that this way:") 
print (f"We'd have {secret_formula(start_point)} beans, {secret_formula(start_point)} jars, and {secret_formula(start_point)} crates.") 

它打印這個

We can also do that this way: 
We'd have (500000, 500, 5) beans, (500000, 500, 5) jars, and (500000, 500, 5) crates. 

回答

2

我看你是以下LPTHW教程,其中我strongly建議你拿起一個不同的教程,作爲當前一個你必須有一些非常有趣的意見some other issues

回到你的問題:你需要解壓的secret_formula()電話是:

b, j, c = secret_formula(start_point) 

print (f"We'd have {b} beans, {j} jars, and {c} crates.") 

f-strings基本上只是把變量中的字符串中調用它,因爲secret_formula()返回一個元組,當你一個fstring只是調用函數,它將返回並打印元組。

+0

你對Python 3的任何書籍給我嗎? – kunjun

+0

http://sopython.com/wiki/What_tutorial_should_I_read%3F – MooingRawr

+0

如何打印這個代碼與F-字符串? ('{0:_^11}'。格式('hello')) ''' – kunjun

0

這個代碼,我想修復成F-串 print "We can also do that this way:" print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)

相關問題