I just noticed something weird
In python, if I do this
>>> k = 1
>>> j = 2
>>> print k,",",j
1 , 2 # prints this
I expected that it would be:
1,2
Why is there a space between these two, whereas
>>> print str(k) + "," + str(j)
1,2
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first example passes the 3 arguments to
printdirectly, which then converts them to strings and concatenates them together, separated by spaces. The second example first converts and concatenates the string, then passes the entire string toprintas a single argument. If you were to doprint str(k), ",", str(j)instead, you’d get the same result as the first example.Think of
printin terms of how functions work rather than as a keyword. As an example, take:foo('a', 'b', 'c')will pass foo 3 arguments, and then return those 3 arguments joined by spaces,'a b c'.foo('a' + 'b' + 'c')will first create the string'abc', then pass that as a single argument to foo, resulting in foo returning just'abc'.