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 Modules
Python Deep Learning Cookbook - Indra den Bakker
Python Program to Find Factorial of Number Using Recursion
Python List count()
Python Errors and Built-in Exceptions
Python Program to Compute the Power of a Number
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python Decorators
Python Function Arguments
Python Set intersection_update()
Python Set difference()
Python Program to Sort Words in Alphabetic Order
Python all()
Python String center()
Python String lstrip()
Python Program to Find the Factorial of a Number
Python globals()
Python Dictionary get()
Python Program to Create Pyramid Patterns
Python getattr()
Python String lower()
How to Get Started With Python?
Python Program to Print Output Without a Newline
Python Program to Display Powers of 2 Using Anonymous Function
Python String format_map()
Python __import__()
Python break and continue
Python dir()
Python bytes()
Python Program to Get the Full Path of the Current Working Directory
Python Global, Local and Nonlocal variables
Python Object Oriented Programming