Table of Contents
In this tutorial, we will learn about the Python input() function with the help of examples.
The input() method takes input from the user and returns it.
Example
name = input("Enter your name: ")
print(name)
# Output: Enter your name: "Sheeran"
# Sheeran
1. input() Syntax
The syntax of input() method is:
input([prompt])
2. input() Parameters
The input() method takes a single optional argument:
- prompt (Optional) – a string that is written to standard output (usually screen) without trailing newline
3. input() Return Value
The input() method reads a line from the input (usually from the user), converts the line into a string by removing the trailing newline, and returns it.
If EOF is read, it raises an EOFError exception.
4. Example 1: How input() works in Python?
# get input from user
inputString = input()
print('The inputted string is:', inputString)
Output
Python is interesting. The inputted string is: Python is interesting
5. Example 2: Get input from user with a prompt
# get input from user
inputString = input('Enter a string:')
print('The inputted string is:', inputString)
Output
Enter a string: Python is interesting. The inputted string is: Python is interesting
Related posts:
Python String isalpha()
Python object()
Python Program to Find the Factorial of a Number
Python Variables, Constants and Literals
APIs in Node.js vs Python - A Comparison
Python Program to Count the Number of Occurrence of a Character in String
Python Program to Find the Factors of a Number
Python locals()
Python Data Types
Python Program to Trim Whitespace From a String
Python Program to Check the File Size
Python Program to Capitalize the First Character of a String
Python Dictionary keys()
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python Set issuperset()
Python Program to Convert Decimal to Binary Using Recursion
Python hex()
Python any()
Python String title()
Machine Learning with Python for everyone - Mark E.Fenner
Python Set discard()
Python String rjust()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Add Two Numbers
Python Dictionary items()
Python set()
Python Machine Learning - Sebastian Raschka
Python Program to Compute the Power of a Number
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Find Hash of File
Python Iterators
Python List Comprehension