0
0
Pythonprogramming~5 mins

Taking input using input() in Python

Choose your learning style9 modes available
Introduction

We use input() to get information from the person using the program. It helps the program to ask questions and get answers.

When you want to ask the user for their name.
When you need the user to enter a number to calculate something.
When you want to get a choice from the user, like yes or no.
When you want to make the program interactive by asking questions.
When you want to get any text or data typed by the user.
Syntax
Python
variable = input(prompt)

prompt is the message shown to the user to explain what to type.

The input() function always returns text (a string).

Examples
Ask the user to type their name and save it in name.
Python
name = input("Enter your name: ")
Ask the user for their age as text. You may need to convert it to a number later.
Python
age = input("Enter your age: ")
Ask the user to type something without showing a message.
Python
color = input()
Sample Program

This program asks the user for their name and age, then says hello using the information.

Python
name = input("What is your name? ")
age = input("How old are you? ")
print(f"Hello, {name}! You are {age} years old.")
OutputSuccess
Important Notes

Remember, input() always gives text. To use numbers, convert with int() or float().

If you forget to add a prompt, the program will wait silently for input.

Summary

input() lets your program talk to the user and get answers.

Always use a prompt to help the user know what to type.

Input is text, so convert it if you need numbers.