PYnative

Python Programming

  • Learn Python
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises
    • Python Exercises
    • C Programming Exercises
    • C++ Exercises
  • Quizzes
  • Code Editor
    • Online Python Code Editor
    • Online C Compiler
    • Online C++ Compiler
Home » Python » Python Input: Take Input from User

Python Input: Take Input from User

Updated on: February 24, 2024 | 42 Comments

In Python, Using the input() function, we take input from a user, and using the print() function, we display output on the screen. Using the input() function, users can give any information to the application in the strings or numbers format.

After reading this article, you will learn:

  • Input and output in Python
  • How to get input from the user, files, and display output on the screen, console, or write it into the file.
  • Take integer, float, character, and string input from a user.
  • Convert the user input to a different data type.
  • Command-line input
  • How to format output.

Also, Solve

  • Python Input and Output Exercise 
  • Python Input and Output Quiz

Table of contents

  • Python Input() function
    • What is the input?
    • Python Example to Accept Input From a User
    • How input() Function Works
    • Take an Integer Number as input from User
    • Take Float Number as a Input from User
    • Practice Problem
    • Get Multiple inputs From a User in One Line
    • Accept Multiline input From a User
    • Python Input() vs raw_input()
  • Command Line input
    • Python sys module
  • Output in Python
  • Output Formatting
    • str.format() to format output
    • Format Output String by its positions
    • Accessing Output String Arguments by name
    • Output Alignment by Specifying a Width
    • Specifying a Sign While Displaying Output Numbers
    • Display Output Number in Various Format
      • Display Numbers as a float type
    • Output String Alignment
  • Next Steps

Python Input() function

In Python 3, we have the following two built-in functions to handle input from a user and system.

  1. input(prompt): To accept input from a user.
  2. print(): To display output on the console/screen.

In Python 2,we can use the following two functions:

  1. input([prompt])
  2. raw_input([prompt])

The input() function reads a line entered on a console or screen by an input device such as a keyboard, converts it into a string. As a new developer, It is essential to understand what is input in Python.

What is the input?

The input is a value provided by the system or user. For example, suppose you want to calculate the addition of two numbers on the calculator, you need to provide two numbers to the calculator. In that case, those two number is nothing but an input provided by the user to a calculator program.