We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Explanation
Python's Print Function defines the input as *objects, not as iterable like it does for Map.
An example of an iterable is a list because we can keep stepping through the elements one at a time.
print instead needs multiple arguments for each object you want to print. * is a way to "unpack" a list so that it becomes arguments instead of a list. *[1,2,3] converts to (1,2,3).
Example using print (from future in py2):
print([1,2,3])
[1, 2, 3]
print(*[1,2,3])
1 2 3
print(1,2,3)
1 2 3
The last two exhibit the desired result, you just need to set sep='' to get 123 (w/o spaces).
Source: JBallin
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Print Function
You are viewing a single comment's thread. Return to all comments →
[1, 2, 3]
print(*[1,2,3])
1 2 3
print(1,2,3)
1 2 3
The last two exhibit the desired result, you just need to set sep='' to get 123 (w/o spaces). Source: JBallin