+ 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 ?
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.
+ 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.
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