Back to Browse

Python print() function to display output using sep end file and flush options

943 views
Nov 29, 2020
12:50

https://www.plus2net.com/python/print.php Python print() function is used to print output to screen or file. Data of any object or variable can be printed by using print() function. Example of string output Print(‘hello world’) We can use format to print out put Id=5 Name=’Ronal Jack’ Mark=45 Print(‘id : {:02d} Name: {:15s} mark: { :2d}”.format(id,name,mark)) Output Id : 05 Name : Ronal Jack mark: 45 We can change the sequence of the variable printing inside the print() function str1="Welcome " str2=" to " str3=" Python " str4=" Your student id = " id=5 print(" Hi {2} {1} {0} ".format(str1,str2,str3)) print(" Hi {0} {1} ".format(str4,id)) We can print decimal places also. my_str="Mr ABCD" avg=356.23456 id=5 name="Welcome to Python" print("Hi {}, Your id = {}, Your Average ={:.2f})".format(my_str,id,avg)) Python adds one line break ( default value of end='\n' ) after each print command, we can remove the line break ( Watch the end='' within the print ()) Sep We can add a separator in between strings print('welcome','to','plus2net', sep='-') multiple string addition with + print( ‘welcome ‘ + ‘to’ + ‘python’)

Download

1 formats

Video Formats

360pmp415.3 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Python print() function to display output using sep end file and flush options | NatokHD