Kuntal Ojha
Kuntal Ojha

Reputation: 21

What will be the output

Program

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)

Output

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

Why not this OUTPUT

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

Answers (1)

Utpal Kumar
Utpal Kumar

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.

Program

a=30
b=444.78
c="\nkuntal Ojha"
d='\nKunal Ojha\n'
e='''Srabanti & Kuntal'''
print(a,b,c,d,e, sep='')

Output

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

Related Questions