Category Archives: input & output

Input/output :-

input() and print() function are used for standard input and output operations.

Output function:-

print() function is used for output operation.As shown here:-

>>> print("Hello Python..!!")
'Hello Python..!!'
>>> num = 7
>>> print("The value of num is ",num)
The value of num is 7

As we can see above that a space was added between the string and the value of variable a by default.The actual syntax of the print() function is :-

print(*objects, sep=' ', end='n', file=sys.stdout, flush=False)

here objects is the value to be printed.sep is the separator used between the values.By default it is space character. end is printed after printing all the values.file is the object where the values are printed and its default value is sys.stdout(screen).
Example is shown here:-
Untitled

Output Formatting :-
str.format()
is used for output formatting.As:-

>>> a = 1; b= 2
>>> print('value of a is {0} and b is {1}'.format(a,b))
value of a is 1 and b is 2
>>> print('value of a is {1} and b is {0}'.format(a,b))
value of a is 2 and b is 1

curly braces {} are used as placeholders

input function :-
Sometimes we want to take input from the user. The input() function allow this.As shown here:-

>>> name = input("Enter your name :-")
Enter your name :- python
>>> name
'python'