Home > Enterprise >  Consider a String a f-string in Python
Consider a String a f-string in Python

Time:09-22

Suppose I have

x = 3 
s = "f'12{x}4'"

How to consider s as f-string to print 1234, like writing print(f'12{x}4') when I print s, it prints it as it as: f'12{x}4'

CodePudding user response:

Remve the double quotations that should fix the issue because the f in a f string needs to be outside the actuall string

CodePudding user response:

You'd do this -

x = 3
s = f'12{x}4'

CodePudding user response:

This can also work.

x = 3 
s = "12{}4"
print(s.format(x))

CodePudding user response:

Just remove extra commas

s = f'12{x}4'
  • Related