Click here

Thursday, September 13, 2018

Python - Print without newline and space


In python , by default print inserts newline character at the end of an output

For example:



Output
1
2

1) To ignore the new line at the end of an output, you can do it multiple ways

In python 2.x



Output
1 2

2) To ignore the space in between



Output
12

Using backspace character replaces the space in between. Comma at the end replaces the newline character with an empty string.  If you use + operator , both the operators has to be in string format

3) To print without using string



Output
12

Comma at the end replaces the new line character. Printing an empty string suppresses the space in between

4) Python 3.x has an easy way of doing this



Using end statement, replaces the end terminator with an empty string.

print('a', 'b', 'c', sep='')
to suppress the white space separator between items.





No comments:

Post a Comment

Omicron - people gathers in crowd

Amidst omicron thread, people are gathered in crowd at markets and public places to buy their daily needs. Because of full lockdown at Sunda...