Reputation: 21
This is my program
a=30
b=444.78
c="\nkuntal Ojha"
d='\nKunal Ojha\n'
e='''Srabanti & Kuntal'''
print(a,b,c,d,e)
In this output I can't understand whay for printing e take a space before it's print.
30 444.78
kuntal Ojha
Kunal Ojha
Srabanti & Kuntal
Tell Which out put is right first one or this one. please tell me with the the example. I am a new #phthon learnar help me to know more about python
30 444.78
kuntal Ojha
Kunal Ojha
Srabanti & Kuntal
Upvotes: 2
Views: 64
Reputation: 300
This is because of the default value of the sep
is a space.
When it prints d
, it ends with \n
, moving the cursor to new line, after which print
function adds a space (default separator) and prints value of e
.
To eliminate it, we can change the default sep
value.
a=30
b=444.78
c="\nkuntal Ojha"
d='\nKunal Ojha\n'
e='''Srabanti & Kuntal'''
print(a,b,c,d,e, sep='')
30444.78
kuntal Ojha
Kunal Ojha
Srabanti & Kuntal
If you pay attention, there is no space between value of a
and b
because we changed the sep
to ''
(nothing).
Upvotes: 2