3 ms·
greet = lambda x: f"hello {x}"
by sumzup 6y ago
greet = lambda x: f"hello {x}"
- linkdd 6y agoWhat if "hello {x}" is not a static string but was read from somewhere else? Surely this would not work: greeting = "hello {x}" greet = lambda x: f greeting
- staticassertion 6y agoSomething along the lines of... code = 'f"{input()} {x}"' lambda x: eval(code) (Please don't do this)
- linkdd 6y agoYes, I'll stick to using str.format :)
- staticassertion 6y agocode = 'f"here it is {eval(input())}"' (lambda: eval(code))() k, there we go
- AlphaSite 6y agoYou can’t use f-strings for that.
- linkdd 6y agoThat was exactly my point.
- klyrs 6y agoThat isn't the purpose for f-strings. You still have % and .format