Reputation: 1
import numpy as np
a =np.array([1, 3, 0, 2], int)
b =np.array([5, 2, 1, 2], int)
print(f'{a > b = }')
a > b = array([False, True, False, False])
import numpy as np
a =np.array([1, 3, 0, 2], int)
b =np.array([5, 2, 1, 2], int)
def myprn(text):
print(f'{text = }')
myprn(a > b)
text = array([False, True, False, False])
#^^^ how to fix this requirement?
Upvotes: -1
Views: 358
Reputation: 1
@Tomerikoo's comment
The only way I can think to make something similar to this work is print(f'{text} = {eval(text)}') and then passing the function strings with the expression, i.e. myprn('a > b')
Upvotes: -1
Reputation: 2195
You can't, =
in f-string is self-documenting sign which just prints expression before it as is. Doc reference
Upvotes: 2