Posts

Showing posts with the label formatted printing

7.Output and Input functions- print() and input()

Python Output Using print() function We use the print() function to output data to the standard output device (screen) An example of its use is given below. >>>print('This is a sample output') This is a sample output Another example is given below: >>>x = 5  >>>print('The value of x is', x) The value of a is 5 The actual syntax of the print() function is: print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) Here, objects is the value(s) to be printed. The sep separator is used between the values. It defaults into a space character. After all values are printed, end is printed. It defaults into a new line. The file is the object where the values are printed and its default value is sys.stdout (screen). flush: Whether to forcibly flush the stream. >>>print(1, 2, 3, 4, sep='*')  1*2*3*4 >>>print(1, 2, 3, 4, sep='#', end='&') 1#2#3#4& Output formatting Sometimes we would...