Taking Input in Python

To get data or provide a certain kind of result, developers find the need to interact with users. Dialog boxes are the most common way of asking inputs from the users. Python for data science houses two inbuilt functions to read input from the keyboard i.e., raw_input( promt) and input ( prompt).input and output in python for data science

raw_input ():

This function is there in the older version of Python like Python 2.x. It takes the input typed on the keyboard as it is, convert it to a string and returns it in the form of a variable in which we desire to store it.

# use of raw_input() in Python language

g = raw_input(“Enter your name : “)

print g


Enter your name :PSTAnalytics



In this example, is a variable that gets the string value that the user typed during the program execution. Enter key is there to terminate the typing of data for raw_input() function. Typecasting is there to enter numeric values.

Input ():

In this function, Python automatically identifies the input by the user as string or list or a number. It takes the input from the user first and then evaluates the expression. If the user enters an invalid input, then we will see either a syntax error or an exception being raised by Python when we apply it in data science. Let’s consider the following example.

# use of input()

#in Python program

val = input(“Enter your value: “)



Enter your value: 852



Working of input function in Python:
  • Program flow is stopped when input() function executes. To continue program flow a user has to give input.
  • The message display or text on the output screen, which asks the user to enter input value is optional.
  • Input function converts everything to a string irrespective of the type of input. If we enter an integer value then also it will get converted to a string by the input() function. Typecasting is there  to convert it into integer form explicitly.

# Program to check input

#type in Python

num = input (“Enter number :”)


name1 = input(“Enter name : “)


# Printing type of input value

print (“type of number”, type(num))

print(“type of name”, type(name1))


Enter number : 741


Enter name :PSTAnalytics


type of number <class ‘str’>

type of name <class ‘str’>


To read more, you can check this.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.