Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to read string from terminal in Python

📅 2015-Jan-02 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ input, python ⬩ 📚 Archive

Reading a character or string from the terminal is a basic operation in most languages. It is most commonly used for a quick debug or analysis of the program.

To do this in Python 2.x:

print "Enter something:"
s = raw_input()
print "You entered:", s

To do this in Python 3.x:

print("Enter something:")
s = input()
print("You entered:", s)

Note that in Python 2.x, the built-in function is raw_input, while it has been renamed to input in Python 3.x.

Tried with: Ubuntu 14.04