How to use input() in Python?

QuestionsQuestions8 SkillsProYour First Python LabOct, 25 2025
0149

In Python, the input() function is used to take input from the user. Here's how to use it:

Basic Usage

  1. Prompt the User: You can provide a prompt message that will be displayed to the user.
  2. Store the Input: The input from the user is returned as a string, which you can store in a variable.

Syntax

variable_name = input("Your prompt message here: ")

Example

# Asking for the user's name
name = input("What is your name? ")
print("Hello, " + name + "!")

Key Points

  • The input is always returned as a string. If you need a different type (like an integer), you must convert it using functions like int() or float().
  • You can use the input in various ways, such as for calculations, conditions, or storing user preferences.

Example with Type Conversion

# Asking for the user's age and converting it to an integer
age = int(input("How old are you? "))
print("You are " + str(age) + " years old.")

Feel free to ask if you have more questions or need further examples!

0 Comments

no data
Be the first to share your comment!