Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Python input() Function
Next article icon

Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. While Python provides us with two inbuilt functions to read the input from the keyboard.


input () function first takes the input from the user and converts it into a string. The type of the returned object always will be <class 'str'>. It does not evaluate the expression it just returns the complete statement as String.

For example, Python provides a built-in function called input which takes the input from the user. When the input function is called it stops the program and waits for the user's input. When the user presses enter, the program resumes and returns what the user typed.

Python
# Python program showing# a use of input()val=input("Enter your value: ")print(val)

Output:

Taking String as an input:

Python
name=input('What is your name?\n')# \n ---> newline  ---> It causes a line breakprint(name)

Output:

What is your name?
Ram
Ram

How the input function works in Python :

Code:

Python
# Program to check input# type in Pythonnum=input("Enter number :")print(num)name1=input("Enter name : ")print(name1)# Printing type of input valueprint("type of number",type(num))print("type of name",type(name1))

Output:


Note: input() function takes all the input as a string only

There are various function that are used to take as desired input few of them are : -

  • int(input())
  • float(input())
Python
num=int(input("Enter a number: "))print(num," ",type(num))floatNum=float(input("Enter a decimal number: "))print(floatNum," ",type(floatNum))

Output:

Output
Output

Refer to the article Taking list as input from the user for more information.


input() in Python
Visit Courseexplore course icon
Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp