Python input() Function – Taking User Input

Any Software System or program written in any programming language at the end would be used by some user. So there need to be some way to send data inside a software system. For this Python uses built-in function input(), which asks user to enter some data( like string, number).
So input() function would put a hold on execution of program until something is entered by user. Once user enter something Python Program would take it in and further execute the program.
Quite Simple. Below are some examples showing use of input() function in a Python Program.

Example 1

some_input = input()
#Asking user for some input, without showing any message

Example 2

some_input = input("Enter some name: ")
#Putting some string inside input() function would prompt user the message first and
#then wait for user to enter the value

Do note that whatever is entered by user will be treated as string by Python. So enter 18 will be a string, but if specifically you want to treat this as a number internally in the program. Then you have to use type casting functions like int()

Example 3

some_input = int(input())
# type of some_input variable will be interger not string

Read More About Python

Gagan

Hi, there I'm founder of ComputerScienceHub(Started this to bring useful Computer Science information just at one place). Personally I've been doing JavaScript, Python development since 2015(Been long) - Worked upon couple of Web Development Projects, Did some Data Science stuff using Python. Nowadays primarily I work as Freelance JavaScript Developer(Web Developer) and on side-by-side managing team of Computer Science specialists at ComputerScienceHub.io

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts