I need print(f"" + xx) to output text aaa but it outputs {x} how could i make this work?
I have tried with printf and .format but couln't make any of those to work
x = "aa"
xx = "text {x}"
x = "aaa"
print(f"" + xx)
I need print(f"" + xx) to output text aaa but it outputs {x} how could i make this work?
I have tried with printf and .format but couln't make any of those to work
x = "aa"
xx = "text {x}"
x = "aaa"
print(f"" + xx)
You need to put the variable you are trying to print within f"{}":
x = "aa"
xx = "{x}"
x = "aaa"
print(f"{x}")
Otherwise, xx is literally "{x}" and is not expanded.
I think you want to use str.format, not an f-string.
xx = "text {x}"
x = "aaa"
print(xx.format(x=x)) # -> text aaa
Or without passing x explicitly:
print(xx.format(**locals())) # -> text aaa