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 Dictionary setdefault()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python __import__()
Python Set symmetric_difference()
Python Object Oriented Programming
Python List reverse()
Python Functions
Python String join()
Python Program to Display Calendar
Python Tuple count()
Python Program to Find the Largest Among Three Numbers
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Compute all the Permutation of the String
Python Program to Differentiate Between del, remove, and pop on a List
Python min()
Python float()
Python super()
Python String zfill()
Python String split()
Python Program to Print all Prime Numbers in an Interval
Python Dictionary
Python Program to Illustrate Different Set Operations
Python Data Types
Python Program to Count the Occurrence of an Item in a List
Python Program Read a File Line by Line Into a List
Python Program to Check If a String Is a Number (Float)
Python Tuple
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python type()
Python Program to Reverse a Number
Python Set union()
Python String rindex()