Skip to content

Instantly share code, notes, and snippets.

@amelieykw
Created July 14, 2018 21:31
Show Gist options
  • Save amelieykw/7efdba4d3a2f3f2bb0127f8c3e75a3cb to your computer and use it in GitHub Desktop.
Save amelieykw/7efdba4d3a2f3f2bb0127f8c3e75a3cb to your computer and use it in GitHub Desktop.
[Python - end parameter in print()] #Python #end #print() #interview #tutorial

By default python’s print() function ends with 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. You can end a print statement with any character/string using this parameter.

# This Python program must be run with
# Python 3 as it won't work with 2.7.
 
# ends the output with a <space> 
print("Welcome to" , end = ' ') 
print("GeeksforGeeks", end = ' ')

Output :

Welcome to GeeksforGeeks

One more program to demonstrate working of end parameter.

# This Python program must be run with
# Python 3 as it won't work with 2.7.
 
# ends the output with '@'
print("Python" , end = '@') 
print("GeeksforGeeks")

Output :

Python@GeeksforGeeks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment