© 2019 BrainStemSchool.com

December 13, 2016

December 9, 2016

December 7, 2016

Please reload

Print Two Things On The Same Line

November 28, 2016

 

https://youtu.be/jAXANpLRcmE

 

Short and sweet today:

 

You can tell print() not to print the newline character at the end of the line with:

 

print("Hello",end='')

print("World")

 

To create the following output:

 

HelloWorld


You can change the print zone separator character with: 


print("Age",25,"Name","Bob","Cash",12.54,sep="|")


To create the following output:

 

Age|25|Name|Bob|Cash|12.54

 

Or to output a comma separated list: you can change the print zone separator character with: 


print("Age",25,"Name","Bob","Cash",12.54,sep=",")


To create the following output:

 

Age,25,Name,Bob,Cash,12.54

 

Use "\t" for the tab character as separator to output for a tab separated list.

 

And in the spirit of making things useful, you can format for HTML newlines with: 

 

print("Hello",end="<br />\n")

print("World",end="<br />\n")

 

Which outputs as:

 

Hello<br />

World<br />

 

But in a web browser it looks like: 

 

Hello

World

 

Next Post: Comments

Share on Facebook
Share on Twitter
Please reload

Please reload

Recent Posts
Tags