Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python 3 - input() function
Next article icon

Python 3 - input() function

Last Updated : 07 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, we use the input() function to take input from the user. Whatever you enter as input, the input function converts it into a string. If you enter an integer value still input() function converts it into a string.

Python input() Function Syntax

Syntax: input(prompt)

Parameter:

  • Prompt: (optional) The string that is written to standard output(usually screen) without newline.

Return: String object

How input() Function works in Python?

In this example, we are using input() function to input user data as a string in Python.

Python
name = input("What is your name? ") print("Hello, " + name + "!") 

Output

What is your name? GFG
Hello, GFG!

input() Function in Python Examples

Taking input in Python

In this example, we are using the Python input() function to input user data as a string in Python, which takes input from the user and prints it.

Python
# Taking input from the user string = input()  # Output print(string) 

 Output

geeksforgeeks

User Input in Python

In this example, we are taking input from the user and input user data as a string in Python with a prompt and printing it.

Python
# Taking input from the user name = input("Enter your name")  # Output print("Hello", name) 

 Output

Enter your name:ankit rai
Hello ankit rai

Convert User Input to a Number

In this example, we are using the Python input() function which takes input from the user in string format converting it into an integer adding 1 to the integer, and printing it.

Python
# Taking input from the user as integer num = int(input("Enter a number:")) add = num + 1  # Output print(add) 

Output

Enter a number:15
16

Take float input in Python

In this example, we are using the Python input() function which takes input from the user in string format converts it into float adds 1 to the float, and prints it.

Python
# Taking input from the user as float  num =float(input("Enter number ")) add = num + 1  # output print(add) 

Output

Enter number 5
6.0

Python Accept List as a input From User

In this example, we are taking input from the user in string format converting it into a list, and printing it.

Python
# Taking input from the user as list  li =list(input("Enter number "))  # output print(li) 

Output

Enter number 12345
['1', '2', '3', '4', '5']

Take User Input for Tuples and Sets

In this example, we are taking input from the user in string format converting it into a tuple, and printing it.

Python
# Taking input from the user as tuple  num =tuple(input("Enter number "))  # output print(num) 

Output

Enter number 123
('1', '2', '3')

Input with a dictionary comprehension

In this example, we are taking the words separated by space to input user data as a string in Python, and we make a dictionary of the word as the key with their length as the value.

Python
words_str = input("Enter a list of words, separated by spaces: ") words = {word: len(word) for word in words_str.split()} print(words) 

Output

Enter a list of words, separated by spaces: geeks for geeks
{'geeks': 5, 'for': 3}

Next Article
Python 3 - input() function

A

ankthon
Improve
Article Tags :
  • Python
  • python-input-output
Practice Tags :
  • python

Similar Reads

    Python Tutorial | Learn Python Programming Language
    Python Tutorial – Python is one of the most popular programming languages. It’s simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio
    10 min read
    Input and Output in Python
    Understanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython input() function is
    8 min read

    Python basic I/O Techniques

    Taking input in Python
    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 ()
    3 min read
    Python input() Function
    Python input() function is used to take user input. By default, it returns the user input in form of a string.input() Function Syntax: input(prompt)prompt [optional]: any string value to display as input messageEx: input("What is your name? ")Returns: Return a string value as input by the user.By de
    4 min read
    Taking input from console in Python
    What is Console in Python? Console (also called Shell) is basically a command line interpreter that takes input from the user i.e one command at a time and interprets it. If it is error free then it runs the command and gives required output otherwise shows the error message. A Python Console looks
    2 min read
    Python - Print Output using print() function
    Python print() function prints the message to the screen or any other standard output device. In this article, we will cover about print() function in Python as well as it's various operations.Python# print() function example print("GeeksforGeeks") a = [1, 2, 'gfg'] print(a) print() Function Syntax
    4 min read
    Python - Output Formatting
    In Python, output formatting refers to the way data is presented when printed or logged. Proper formatting makes information more understandable and actionable. Python provides several ways to format strings effectively, ranging from old-style formatting to the newer f-string approach.Formatting Out
    5 min read

    Python3 I/O

    Different Input and Output Techniques in Python3
    An article describing basic Input and output techniques that we use while coding in python. Input Techniques 1. Taking input using input() function -> this function by default takes string as input.  Example: Python3 #For string str = input() # For integers n = int(input()) # For floating or deci
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
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 our Cookie 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