I am currently learning basic python, and was wondering what would be the difference between these 2 pieces of code:
name = input("What is your name?") print("Hello " name)
name = input("What is your name?") print("Hello ", name)
I'm sorry if this question seems stupid, I've tried looking on google but couldn't find an answer that quite answered my question.
CodePudding user response:
In this example, you have to add an extra whitespace after Hello.
name = input("What is your name?") print("Hello " name)
In this example, you don't have to add an extra whitespace (remove it). Python automatically adds a whitespace when you use comma here.
name = input("What is your name?") print("Hello ", name)
CodePudding user response:
The difference between the two pieces of code is the way in which the name variable is concatenated with the string "Hello" in the print() statement. In the first example, the operator is used to concatenate the two, while in the second example, a comma is used to separate the two values
CodePudding user response:
print('a' 'b')
Result: ab
The above code performs string concatenation. No space!
print('a','b')
Result: a b
The above code combines strings for output. By separating strings by comma, print() will output each string separated by a space by default.