The code is written to print no.s upto user defined range in a single line without using string. What is the use of " * " ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The code is written to print no.s upto user defined range in a single line without using string. What is the use of " * " ?

print(*range(1, int(input())+1), sep=' ')

29th Aug 2018, 7:33 PM
Ayan Biswas
Ayan Biswas - avatar
2 Answers
+ 4
If you use print(range(10), sep=', '), it will just print 'range (0, 10)'. If you use print(*range(10), sep=', '), it will print '0, 1, 2, 3, 4, 5, 6, 7, 8, 9'. The asterisk evaluates the expression and will print the actual content of the expression rather than the outline.
29th Aug 2018, 8:34 PM
Anna
Anna - avatar
+ 3
Man lernt nicht aus 🎓
29th Aug 2018, 8:42 PM
Sebastian Keßler
Sebastian Keßler - avatar