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 enumerate()
Python Program to Check Leap Year
Python Program to Split a List Into Evenly Sized Chunks
Python Program to Merge Two Dictionaries
Python help()
Python Program to Create Pyramid Patterns
Python Program to Convert String to Datetime
Python Multiple Inheritance
Python String islower()
Python Shallow Copy and Deep Copy
Python ascii()
Python Deep Learning Cookbook - Indra den Bakker
Python Data Types
Python round()
Python range()
Python Program to Remove Duplicate Element From a List
Python complex()
Python for Loop
Python Program to Find Hash of File
Python String ljust()
Python str()
Node.js vs Python for Backend Development
Machine Learning Applications Using Python - Cases studies form Healthcare, Retail, and Finance - Pu...
Python Variables, Constants and Literals
Python Program to Find Factorial of Number Using Recursion
Python Set isdisjoint()
Python Program to Make a Simple Calculator
Python Object Oriented Programming
Python Dictionary setdefault()
Python Dictionary copy()
Python Program to Find HCF or GCD
Python Strings