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

Python basic tutorial

Flow control in Python

Fonctions en Python

Types de données en Python

File operations in Python

Objects and classes in Python

Python date and time

Advanced knowledge of Python

Python reference manual

Usage and examples of Python input()

Built-in functions in Python

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

The syntax of 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:

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

Example2: Prompt user to input

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

When running the program, the output is:

Input string: fr.oldtoolbag.com Python basic tutorial
The input string is: fr.oldtoolbag.com Python basic tutorial

Built-in functions in Python