Python Output Statement

Python use print() function for displaying data on screen/terminal. This is also know as standard output function. In python programming print() function is also used for displaying formatted output.

Print function can also be used to write data/output on the secondary storage files. The contents are provided as paramter to the print() function.

Python print() function Syntax

Syntax of print function in python language is as:

print( *objects , separator = ' ' , terminator = '\n' , file = sys.stdout , flush = false )

Where:

  • Objects are the first parameter that may be string or variables (spearated by comma)
  • After object output separator can be specified by default this is a space.
  • Third parameter is the output/ line terminator which by default change the line for new output.
  • Next parameter is file which is by default used as stdout refers to the screen.

Display String/Text Using print() function

To display or show simple text on the screen we just provide string of characters enclosed in single or double quotes as parameter.

Example using double quotes

print("Text output using double quote")

Example using single quotes

print('Text output using Single quote')

Multiple strings can also be provided as input to print function separated by comma.

print("First String ","Second String")

Display Variable Value

Similar to strings we can also provide variable name as the parameter of the print function. Value of the variable will be displayed on the screen. We can provide multiple variable names separated by comma.

Display Single Variable

x = 10
print(x)

Display Multiple Variables

x = 10
y = 20
z = 30
print(x)
print(y)
print(z)

Output

10
20
30

Each variable value will be print in single line, because default line end parameter in print function is \n. Which mean to change the line

If we set other end of line parameter than output will be displayed in single line such as:

a = 50
b = 60
c = 70
print(a,b,c,end='.')

Output

50 60 70.

 

 
 
 
Comments
Login to TRACK of Comments.