By default Python‘s print() function ends with a newline. A programmer with C/C++ background may wonder how to print without a newline. Python’s print() function comes with a parameter called ‘end‘. By default, the value of this parameter is ‘\n’, i.e. the new line character.
Here, we can end a print statement with any character/string using this parameter.
# ends the output with a space print ( "Welcome to" , end = ' ' ) print ( "programmingshark" , end = ' ' ) |
Output:
Welcome to programmingshark
One more program to demonstrate the working of the end parameter.
Output:
Python@programmingshark
The print() function uses the sep parameter to separate the arguments and ends after the last argument.
print('G','F', sep='', end='')
print('G')
#\n provides new line after printing the year
print('09','12','2016', sep='-', end='\n')
print('Red','Green','Blue', sep=',', end='@')
print('programmingshark')
Output
GFG 09-12-2016 Red,Green,Blue@programmingshark