Python
Python Functions Examples: Call, Indentation, Arguments & Return Values
What is Function in Python? A Function in Python is a piece of code which runs when it is...
In this tutorial, you will learn-
More often then not you require to Print strings in your coding construct.
Here is how to do it in Python 3
Example: 1
To print the Welcome to gtupapers, use the print () function as follows:
print ("Welcome to gtupapers")Output:
Welcome to gtupapers
In Python 2, same example will look like
print "Welcome to gtupapers"
Example 2:
If you want to print the name of five countries, you can write:
print("USA")
print("Canada")
print("Germany")
print("France")
print("Japan")Output:
USA Canada Germany France Japan
Sometimes you need to print one blank line in your Python program. Following are an example to perform this task.
Example:
Let us print 8 blank lines. You can type:
print (8 * "\n")
or:
print ("\n\n\n\n\n\n\n\n\n")Here is the code
print ("Welcome to gtupapers")
print (8 * "\n")
print ("Welcome to gtupapers")Output
Welcome to gtupapers Welcome to gtupapers
By default, python's print() function ends with a newline. This function comes with a parameter called 'end.' The default value of this parameter is '\n,' i.e., the new line character. You can end a print statement with any character or string using this parameter. This is available in only in Python 3+
Example 1:
print ("Welcome to", end = ' ')
print ("gtupapers", end = '!')Output:
Welcome to gtupapers!
Example 2:
# ends the output with '@.'
print("Python" , end = '@')Output:
Python@
What is Function in Python? A Function in Python is a piece of code which runs when it is...
What are the modules in Python? A module is a file with python code. The code can be in the form...
What is XML? XML stands for eXtensible Markup Language. It was designed to store and transport...
What is Tuple Matching in Python? Tuple Matching in Python is a method of grouping the tuples by...
What is Python Sleep? Python sleep() is a function used to delay the execution of code for the...
Python List data-type helps you to store items of different data types in an ordered sequence. The...