Python Input And Output Statements

Input and Output statements in Python

input() :

Python provides input() built in function to read the input from user using the standard input device (i.e. keyboard). Input function returns the string data irrespective of any datatype it is going to read as user input.

Syntax
Syntax: var_name = input([“interactive statement”])

where,
var_name is the variable assigned with the string value which is read using input method.

Interactive statement is the statement displayed to the user expecting the response from them.

CODE/PROGRAM/EXAMPLE
//Program Example :
input_var=input(“please enter the value”)
	print(input_var)
	
//sample output:
please enter the value100
100	

print():

Python provides print() built in function to print the output on to standard output device (i.e. Monitor)

Syntax
Syntax: print(“var_name1, var_name2, …”, [end=”value1”, sep=”value2”])

where,

var_name1, var_name2 are the variable names or the literals you want to print or output

end is used to specify the separator between two print statements which is ‘ ’ by default

sep is used to specify the separator between the different variables printed using print statement

CODE/PROGRAM/EXAMPLE
//Program Example :
a="bookofnetwork"
	b=20.127
	c=10
	print(a,b,c)
	print(a,b,c,sep=":")
	print(a,b,c,end=" ")
	print(a,b,c)
	print("b=%0.2f" %b)
	print("c=%8d" %c)
	print("c=%-8d" %c)

Output :
bookofnetwork 20.127 10
bookofnetwork:20.127:10 #seperator between variables changed to ‘:’
bookofnetwork 20.127 10 bookofnetwork 20.127 10 #seperator between two print statement changed to " "
b=20.13 #as the format is 0.2 value is rounded of two decimal digits
c =      10 #right aligned within the reserved 8 spaces 
c =10       #left aligned within the reserved 8 spaces as there is – symbol
#input_and_output_statements_in_python #python_print #print_in_python #python_print_format #python_print_list #python_3_print #python_print_variable #python_print_function

(New page will open, for Comment)

Not yet commented...