-1
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.

3 Answers 3

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

this answers my not so well formulated question. Basically, I want to put the f'{1}{2}{3}' string at the beginning of the code and add in the variables as I go along some if/else statements. I could do it by hand but keeping in mind that I want the possinility of 3 or 4 variables per slot, it's just going to be a huge hassle. I understand this makes the question a million times more complicated, but I can't think of any other way to go about this issue
Then can you try to reformulate your question and make a clear example ?
1

Put the variable names into the f-string.

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

2 Comments

Welcome to Stack Overflow. Please read How to Answer and keep in mind that this is not a discussion forum, but a Q&A site; as such, there are certain requirements for questions, and it is not appropriate to answer questions that don't meet those requirements. If you want to help people with whatever random coding problems (including "I have multiple problems with this code, please debug it for me"), without heed to the format, it would be better to try Reddit or Quora.
Sorry, still learning the ropes here.
1
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.