+ 2
How to put variables in strings (python)
im making a convertsation generator and i need to put variables in strings. for instance print('Hey,' nme) (nme is the variable for the name) but this never works
5 Respuestas
+ 4
Hey dude.
try this out.
you have to use + to join strings.
name = "dome"
print("hello " + name)
+ 1
or try this
print("hello %s" %nme)
+ 1
nme = 'myname'
print('Hello', nme)
This will work at all costs
0
We have formatted texts for it
name = 'John'
greeting = f'Hello {name}!'
print(greeting)
# Outputs: 'Hello John!'
0
suppose:
name = input(" enter your name")
print("hey",name)
output:
the user gives the input as xyz
then it will print as
hey!xyz