Python: .format() and @ symbol | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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?

13th Sep 2020, 8:51 PM
Solus
Solus - avatar
2 Answers
+ 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/
13th Sep 2020, 9:19 PM
Slick
Slick - avatar
+ 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
13th Sep 2020, 10:59 PM
Abhay
Abhay - avatar