0
Python: .format() and @ symbol
def foo(fn): def wrap(): return ">{}".format(fn()) return wrap @foo def something(): return "result" print (something()). #outputs >result The format() method inserts the specified value(s) inside the string's placeholder { }. Question 1: Is the specified value in this case > or fn() ? Question 2: What does the @ symbol do? Question 3: What does function foo have to do with function something? Question 4: Is there any other concept I need to understand to be able to answer this question?
2 Antworten
+ 3
1. yeah, but fstrings are a lot more useful
2., 3. (and mabey 4)i cant explain it better:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2463/
+ 2
1.Obviously the specified value is fn() in this case ,">" is just a symbol or string ,whatever value is passed to format replaces the {}
For 2,3,4 Slick already provided link