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 List copy()
Python zip()
Python Program Read a File Line by Line Into a List
Python filter()
Python Program to Iterate Through Two Lists in Parallel
Python Program to Print Output Without a Newline
Python String format()
Python String find()
Python Program to Concatenate Two Lists
Python String lstrip()
Python open()
Python Program to Compute the Power of a Number
Python Program to Reverse a Number
Python Shallow Copy and Deep Copy
Python List count()
Python abs()
Python id()
Python map()
Python type()
Python Program to Generate a Random Number
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Shuffle Deck of Cards
Python Program to Slice Lists
Python sum()
Python if...else Statement
Python Program to Merge Two Dictionaries
Python File I/O Operation
Python globals()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python Program to Convert Decimal to Binary, Octal and Hexadecimal
Python List append()
Python staticmethod()