How to give input from console in Python?

The answer to this frequent question of beginners:

name = raw_input()
print name


If you want to read an integer -

num = raw_input()
num = int(num)
# raw_input returns string, so convert it to integer

You will also find this post useful: http://love-python.blogspot.com/2010/11/fast-way-to-get-input-from-stdin-python.html

Comments

C.I.O.M. said…
My friend, I humbly suggest you change the style of the page so that the Python code--the most important part of your blog--is in a readable black instead of a low contrast light red. Readability matters (especially for people with visual problems). Thank you!
Tamim Shahriar said…
Thanks for your feedback. Yes, you are right. I shall do experiment with other available templates and choose a better one.

Popular posts from this blog

Strip HTML tags using Python

lambda magic to find prime numbers

Convert text to ASCII and ASCII to text - Python code