+ 1

print(I,) can someone tell me the use of comma ( , )?

for I in range(0,5): print(I,) I have seen this kind of program somwhere is sololearn...can someone tell me why is that comma used ?

3rd May 2020, 3:18 AM
Gaurav Giri
Gaurav Giri - avatar
4 ответов
+ 5
Yes , is used as a separator in many programing language not only in python but here in your print function it is not required because u dont have to separate any thing from l.
3rd May 2020, 3:49 AM
Ayush Kumar
Ayush Kumar - avatar
+ 1
I'd like to add to 𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 and AYUSH.ks's answer. ',' is also used for forcing Python to make a tuple. For example, x = (1) print(type(x)) # outputs <class 'int'> x = (1,) print(type(x)) #outputs <class 'tuple'> This is very useful when your function takes a tuple, and you want to pass one number as a tuple. function_name((x)) Gives the argument as an integer. function_name((x,)) Gives the argument as a tuple.
3rd May 2020, 4:26 AM
XXX
XXX - avatar
0
Many atimes the comma "," in python is used to separate arguments Example Range(2, 40, 3) There are 3 arguments here in parenthesis, seperated by the comma
3rd May 2020, 1:28 PM
Tega Somuvie
Tega Somuvie - avatar