+ 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?
3 ответов
+ 14
print(a,"same line")
here a is a variable
+ 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!
+ 1
Thx