Nothing more is required to explain what does the print function does, it's name is itself self explanatory.
Print function is used to display /print messages into the screen.
Within python we can use ether pair of single inverted commas ' ' or double inverted " " within single brackets ( ) both gives the same result.
Print() with Parameters.
I'm adding some of the print function usage along with various parameters.
Print() with Sep
SEP commonly a short form of separator, Separator between the arguments to print() function in Python is space by default (softspace feature) , which can be modified and can be made to any character, integer or string as per our choice.
Default behaviour of python with softspace.
>>> print('A','B','C')
A B C
#Trick to disable softspace using sep parameter
>>> print('A','B','C',sep='')
ABC
One more example.
>>> print('13','11','2018')
13 11 2018
#Trick to format a date
>>> print('13','11','2018', sep='-')
13-11-2018
Print() with End
End parameter along with print can be used to align data into a same single line along with required character,symbol or word.
Example:
Output:
Now, with help of end parameter, we can allign all these three different lines by one, along with extra characters too
Output:
One more example ( SEP with END )
Output:
Print Formatted strings and Variables on the same line.
Before knowing anything, please note the below abbreviations.
print("formatted String" %(variable list))
Examples.
No comments:
Post a Comment