Computer Science, asked by aman3813, 8 months ago

what type of data is accepted by input function in python.
PLEASE GIVE A GENUINE ANSWER
CLASS 11th

Answers

Answered by modhakrisha2020
6
In Python, we have the following two functions to handle input from a user and system.

input(prompt) to accept input from a user.
print() to display output on the console.
Python 3 has a built-in function input() to accept user input.

In Python 2, to accept user input we can use the following two functions: –

input([prompt])
raw_input([prompt])
The input() function reads a line entered on a console by an input device such as a keyboard and convert it into a string and returns it. As a new developer, It is essential to understand what is input in Python.

What is the input?

The Input is nothing but some value from a system or user. For example, if you want to perform an addition of two numbers on the calculator you need to provide two number to the calculator, those two number is nothing but an input provided by the user to a calculator program.

There are different types of Input, and that comes in various ways. For example: –

Input stems from the keyboard. i.e., the user entered some value using a keyboard.
Input Using Mouse Click or movement, i.e. you clicked on the radio button or some drop-down list and chosen an option from it.
In Python, there are various ways for reading input from the user from the command line environment or through the user interface. In both cases, the user is sending input from Keyboard or mouse.
Answered by AryanAshra0206
8
Getting User Input from Keyboard
There are two functions that can be used to read data or input from the user in python: raw_input() and input(). The results can be stored into a variable.

raw_input() – It reads the input or command and returns a string.

input() – Reads the input and returns a python type like list, tuple, int, etc.

Example
name = raw_input (“what is your name?
”) # return type of raw input is always string
age = input (“what is your age
”) # This can be different from string
print “user entered name as: ” + name
print “The type of the name is: ”,
print type (name)
print “user entered age as: ” + str (age)
print “The type of age is: ”,
print type (age)
Assigning Values after running it:

what is your name?

Course Curriculum
Python Scripting Certification Training
Self-Paced Learning
Real-life Case Studies
Assignments
Lifetime Access
Explore Curriculum
abc

what is your age?

21

It will give the result as follows:

user entered name as: abc

The type of the name is:

user entered age as: 21

Programming & Frameworks Training

JAVA, J2EE & SOA CERTIFICATION TRAINING
Java, J2EE & SOA Certification Training

Reviews
4(39606)
PYTHON SCRIPTING CERTIFICATION TRAINING
Python Scripting Certification Training

Reviews
5(8647)
PYTHON DJANGO TRAINING AND CERTIFICATION
Python Django Training and Certification

Reviews
5(4422)
COMPREHENSIVE JAVA COURSE CERTIFICATION TRAINING
Comprehensive Java Course Certification Training

Reviews
5(16233)
MASTERING PERL SCRIPTING CERTIFICATION TRAINING
Mastering Perl Scripting Certification Training

Reviews
5(4289)
SPRING FRAMEWORK CERTIFICATION TRAINING
Spring Framework Certification Training

Reviews
5(7916)
PHP & MYSQL WITH MVC FRAMEWORKS CERTIFICATION TRAINING
PHP & MySQL with MVC Frameworks Certification Training

Next
The type of the age is:

There was no type given above for the data when entered. Name has been taken as string type, while age has been taken as integer type Python. Basically, the difference between raw_input and input is that the return type of raw_input is always string, while the return type of input need not be string only. Python will judge as to what data type will it fit the best. In case you have entered a number, it will take it as an integer. But if it is raw_input it would certainly be string.

Note: Whenever you write a lot of code, it’s always advisable to write it in one of the IDEs as it is very helpful. In case you do not get proper indentation, it will directly show you errors. If you have any problem as well, it’s very easy to debug in PyCharm or any other IDE that you may want to use.
Similar questions