Programming with Python

  1. Home
  2. Docs
  3. Programming with Python
  4. Input-Output in python

Input-Output in python

Like every programming language python also provides us with two inbuilt functions:-

  1. raw_input(prompt)
  2. input(prompt)

raw_input()-It reads the input or command and returns a string. This means, even when the user inputs an integer value, it will still be considered as a string. This inbuilt function can only be used in Python 2.x and not in Python 3.x.

input()-Reads the input and returns a python type like list, tuple, int, etc. This means if the user enters an integer, an integer will be returned and if the user enters a string, a string will be returned.

The input() method takes a single optional argument:

prompt(optional) – a string that is written to standard output(usually screen) without trailing newline.

This is how it works in Python 2.x versions whereas in Python 3.x versions, input() always returns a string and this function is just a replacement of raw_input() function.

For any output in python, we have to use an in-built function print()

print()- Reads the function and prints it on the screen.

This is all about input-output in python.

Articles

Was this article helpful to you? Yes No

How can we help?