Input and output (IO) is a major part of any programming language - being able to receive inputs and produce outputs are what makes a program interactive.
Output
Output in Python is normally achieved using the print
keyword.
print ("Hello world!")
The print
method also supports multiple values which
it will print in one string separated by a single space:
print ("Hello", "world!")
Input
Input in Python varies based on the version. Version 3.x introduced the input
method of getting an input from the user whereas previous versions relied on
the raw_input
method:
# Prior to Python 3.x print (raw_input("Please insert your name")) # Python 3.x and later print (str(input("Please insert your name")))
Notice in Python 3.x the use of the str
method to convert the input to
an appropriate format.
print
method, they are recommended in most cases. The only time that the brackets are
not necessary is when there is only a single Python expression following it.