Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

printing variable that contains string and 2 other variables

var_a = 8
var_b = 3

var_c = "hello my name is:",var_a,"and",var_b,"bye"
print(var_c)

When I run the program var_c gets printed out like this: ('hello my name is:', 8, 'and', 3, 'bye') but all the brackets etc get printed as well, why is this and is there a way to get rid of those symbols?

If I run the program like this:

print("hello my name is:",var_a,"and",var_b,"bye")

I don't have that problem

like image 588
Blank Blank Avatar asked Sep 08 '17 14:09

Blank Blank


1 Answers

You can format your string to get your expected string output.

var_c = "hello my name is: {} and {}, bye".format(var_a, var_b)

As commented, your existing output is due to the variable being returned as a tuple, whereas you want it as one string.

like image 174
Alexander Avatar answered Sep 20 '22 20:09

Alexander