Home > OS >  Formatted string hell - Python
Formatted string hell - Python

Time:02-01

x = f'{1}{2}{3}'

a = "one"
b = "two"
c = "three"

#I want to print "onetwothree"

I don't even know how to explain this problem, I froze up every time I started typing anything into google. Haven't tried anything yet, since I don't even know where to start. Help.

CodePudding user response:

You can insert the variables' name inside the brackets of the f-string.

a = "one"
b = "two"
c = "three"

print(f'{a}{b}{c}')
>>> onetwothree

CodePudding user response:

Put the variable names into the f-string.

print(f"{a}{b}{c}")

CodePudding user response:

x = f'{1}{2}{3}'

a = "one"
b = "two"
c = "three"

#I want to print "onetwothree"
print(f"{a}{b}{c}")

enter image description here

Explanation: for every variable x, you fill in with {x}. For python 3, you use the print(item) function if you want to print out an item.

The print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen.

  •  Tags:  
  • Related