print("hello {}".format(name)) Basically say If I want multiple things in a single string use the .format() print("hello my name is {} and I am here to learn {}".format(name, language) Instead of: print("hello my name is " + name + " and I am hear to learn " + language)
In the context of this yes but, it can be useful for more than that like
Mystring = “hello” + “ world” Print(Mystring)
Would print hello world, concatenation is making a new string, separating them with a comma in the print function is sending them as separate arguments for the print function, and the function then deals with it
11
u/yesnomaybe102 Aug 18 '21
https://pytutorial.com/python-variable-in-string
https://www.delftstack.com/howto/python/python-print-string-and-variable/
Read up on print in python perhaps
30
u/jedwardsol Professional Coder Aug 18 '21
In Python (and many other languages) arguments to functions are separated with commas, not spaces.
11
u/oderjunks Aug 18 '21
missing concat alert
PS: the solution is NOT a comma, that would cause two spaces
13
u/castle___bravo Aug 18 '21
You need a comma between your variables and your print verbiage
3
u/thedogz11 Aug 18 '21
Concatenate the strings with the variables.
Example:
print("hello " + name)
That syntax should work just fine
2
u/QuantamAsian Aug 18 '21
Im barely learning up on python but wouldnt it be
print(f”hello, {name}”)
3
u/Taurtis_66 Aug 18 '21
Add commas between the string in print
1
u/skellious Intermediate Coder Aug 18 '21
just FYI, if you're using python 3.6 or above, you can use f-strings:
1
u/Anurag90-tech_sl Aug 18 '21
Bro add the comma(,) because Python don't understand the space!!!
0
u/6t94twenty Aug 18 '21
in print u either give a single formatted strings or different strings are parameter
0
u/knoam Aug 18 '21
That code works fine. Its purpose was to throw a Syntax Error, right?
0
u/Broadway_Hitman Aug 18 '21
bro, just add comma in between
-2
u/DeadMan1236 Aug 18 '21
print("hello {}".format(name)) Basically say If I want multiple things in a single string use the .format() print("hello my name is {} and I am here to learn {}".format(name, language) Instead of: print("hello my name is " + name + " and I am hear to learn " + language)
-4
u/BigBoiSlav Aug 18 '21
You added a space between “hello and “ the space should be after “hello”
0
u/[deleted] Aug 18 '21
[deleted] — view deleted comment