Wednesday, 22 September 2021

Python: sep parameter usage in print method

‘print’ method is used to send the objects to the text stream file. By default it send the data to the console.

 

Signature

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

As the name suggest ‘sep’ argument separate the input objects with the specified value and write to the text stream file.

 

Example

print('hello', 'hi', 'there', sep='->')


Above snippet generate below string.

hello->hi->there

 

Find the below working application.

 

print_demo_1.py

print('hello', 'hi', 'there', sep='->')
print('hello', 'hi', 'there', sep=',')


Output

hello->hi->there
hello,hi,there






 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment