How to print simple string?
More often then not you require to Print strings in your coding construct.
Here is how to do it in Python 3
To print the Welcome to prabashanas, use the print () function as follows:
print ("Welcome to prabashanas")
Welcome to prabashanas
In Python 2, same example will look like
print "Welcome to prabashanas"
If you want to print the name of five countries, you can write:
print("USA") print("Canada") print("Germany") print("France") print("Japan")
USA Canada Germany France Japan
How to print blank lines
Sometimes you need to print one blank line in your Python program. Following are an example to perform this task.
Let us print 8 blank lines. You can type:
print (8 * "\n")
Here is the code
print ("Welcome to prabashanas") print (8 * "\n") print ("Welcome to prabashanas")
Welcome to prabashanas Welcome to prabashanas
Print end command
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+
print ("Welcome to", end = ' ') print ("prabashanas", end = '!')
Welcome to prabashanas!
# ends the output with ‘@.’
print("Python" , end = '@')