+ 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

16th Jun 2018, 4:06 AM
VD30
VD30 - avatar
5 odpowiedzi
+ 4
Hey dude. try this out. you have to use + to join strings. name = "dome" print("hello " + name)
16th Jun 2018, 4:11 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 1
or try this print("hello %s" %nme)
16th Jun 2018, 4:36 AM
‎ ‏‏‎Anonymous Guy
+ 1
nme = 'myname' print('Hello', nme) This will work at all costs
16th Jun 2018, 7:38 AM
Rugved Modak
Rugved Modak - avatar
0
We have formatted texts for it name = 'John' greeting = f'Hello {name}!' print(greeting) # Outputs: 'Hello John!'
17th Jun 2018, 10:01 AM
Mustafa Yıldız
Mustafa Yıldız - avatar
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
18th Jun 2018, 3:24 PM
AISHWARYA KASTHALA
AISHWARYA KASTHALA - avatar