English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python Basic Tutorial

Python Flow Control

Python Functions

Python Data Types

Python File Operations

Python Objects and Classes

Python Date and Time

Advanced Python Knowledge

Python Reference Manual

Python input() Usage and Examples

Python Built-in Functions

The input() method reads a line from input, converts it to a string, and returns it.

The syntax of the input() method is:

input([prompt])

input() Parameters

The input() method takes an optional parameter:

  • prompt (optional)  -Write a string to standard output (usually the screen) without a newline character

input() Return Value

The input() method reads a line from input (usually user input), converts it to a string by removing the trailing newline character, and then returns it.

If EOF is read, EOFError exception will be raised.

Example1: How to use input() in Python?

# Get user input
inputString = input()
print('The input string is:', inputString)

When running the program, the output is:

www.oldtoolbag.com
The input string is: www.oldtoolbag.com

Example2: Prompt the user to input

# Get user input
inputString = input('Input string:')
print('The user input string is:', inputString)

When running the program, the output is:

Input string:www.oldtoolbag.com Python Basic Tutorial
The user input string is: www.oldtoolbag.com Python Basic Tutorial

Python Built-in Functions