+ 1

Python. How can I print a variable and a text?

How do I print a variable and a text that I want on the same line?

25th Sep 2020, 9:35 AM
JohnSia2005
3 Respostas
+ 14
print(a,"same line") here a is a variable
25th Sep 2020, 9:35 AM
TOLUENE
TOLUENE - avatar
+ 2
you can use the format function. It's very simple. All you need is a string and a value. Old versions of Python used this syntax: name = 'Victor' print('Hi, my name is {name}'.format(name)) The "old" syntax still works, but you can use a shortcut name = 'Victor' print(f'Hi, my name is {name}') # on the begining of the string, you add an 'f' (abbr from format) and you start your string. When you want to add a variable to the string, use {} and add the variables!
25th Sep 2020, 9:48 AM
Victor
Victor - avatar
+ 1
Thx
25th Sep 2020, 9:36 AM
JohnSia2005