Sep parameter in print() function

Sep parameter in print() function

Sep parameter 


The separator between the arguments to print() function in Python, its identify by space, by default and it is known as softspace feature, which can be modified and can be made to any character, integer or string as per our choice. The ‘sep’ parameter is used to achieve the same, it is found only in python 3.x or later. It is also used for formatting the output strings.

object oriented program, python basic programs, python coding, python ide, python programming for beginners,


Lets see some examples related to this :
  

#code for disabling the softspace feature
print('C','D', sep='')
  
#for formatting a date
print('09','05','2020', sep='-')
  
#another example
print('bikki','codedudle', sep='@')

the strings will separate with the characters which have used in the 'sep'
parameter.

output :

C D

09-05-2020

bikki@codedudle


We have discussed already about the 'end' parameter in print() function,
when we use this with 'sep' parameter its generate an awesome result.

lets see how :


print('C', sep='', end='')
print('D')
#\n provides new line after printing the year
print('09','05', sep='-', end='-2020\n')
  
print('bikki','shaw', sep='', end='@')
print('codedudle')



output :

CD

09-05-2020

bikkishaw@codedudle



And there is a fun thing for you.

Change your language from python to python 3 in the online ide.
Go to your interactive python ide by typing python in your cmd ( windows ) or terminal ( linux )

#import the below module and see what happens
import antigravity
#NOTE - it wont work on online ide


and see what gonna be happen.

do it comment the experience below !


In this article i have explained a detailed view of 'end' parameter











 #matplotlib
 #python 3
 #scikit learn
 #tkinter
 #python training
 #python data analysis
 #best python tutorial
 #python classes near me
 #learn python for beginners
 #python online training
 #django course
 #advanced python course
 #python course fees
 #introduction to data science in python
 #free python tutorial
 #learn python basics
 #python study











































Post a Comment

2 Comments

If you have any doubt, Please let me know.