Input_Output.ipynb - Colaboratory
Input_Output.ipynb - Colaboratory
ipynb - Colaboratory
print() function
It prints the message to the screen or any other standard output device.
Syntax:
Parameters:
value(s): Any value, and as many as you like. Will be converted to a string before printed
sep='separator' : (Optional) Specify how to separate the objects, if there is more than one. Default :' '
file : (Optional) Specfies where we want to route the output. By default it is routed to the console. Default: sys.stdout
flush : (Optional) A Boolean, specifying if the output is flushed (True) or buffered (False). Default: False
account_circle Hello,World
Hello World
# variables
exam_name = "Python"
exam_date = "2-Sept"
exam_score = 400
for i in range(10):
print(i, flush =False)
print(formatted string)
The output can be formatted using the special symbol %
print(“formatted string” % (variables list))
https://colab.research.google.com/drive/16sJfEDATPW0mZHxwhv9LRhc1lz7adsRG#printMode=true 1/3
18/11/2023, 19:20 Input_Output.ipynb - Colaboratory
The statement begins with a format string consisting of a sequence of character and conversion specifications.
Format Symbol-Purpose
%c character
%s string
%o Octal integer
%x or %X Hexadecimal integer
%e or %E Exponential Notation
x,y = 10, 15
print('x = %i, y = %d' %(x,y))
print('%d, %d'%(y,x))
x = 10, y = 15
15, 10
n = 'abc'
print(' %c, %c %s' % (n[0], n[1], n))
a, b abc
input
It reads a string from the user's keyboard. (reads and returns an entire line of input)
Type a number :3
15
#eval() function takes a string and evaluates the result of the string by taking it as a python expression
a,b = 10,20
result = eval('a+b-10')
print(result)
20
center() method is an inbuilt function that is used to align the string to the center by filling paddings to the left and right of the string.
https://colab.research.google.com/drive/16sJfEDATPW0mZHxwhv9LRhc1lz7adsRG#printMode=true 2/3
18/11/2023, 19:20 Input_Output.ipynb - Colaboratory
String.center(length, fillchar)
str1 = 'Hi'
print(str1.center(6))
print(str1.center(6,"@"))
Hi
@@Hi@@
https://colab.research.google.com/drive/16sJfEDATPW0mZHxwhv9LRhc1lz7adsRG#printMode=true 3/3