Jun-04-2023, 01:09 AM
is it OK to set variables in an f-string? i need to call an expensive (e.g. slow) function to get a value that is needed in 3 places in an f-string and again in a 2nd f-string. calling this function 4 times is bad and also can cause other problems. currently i call it once and assign its return value to a short variable and use that in the f-strings. now i'm wanting to squeeze this into one line:
[stupid example code]
[stupid example code]
print(f'{x=stupid_slow_function()} {x} {x} {x}',some_other_big_string,f'foo{x}bar}')[/stupid example code]
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.