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 break and continue
Python Errors and Built-in Exceptions
Python Program to Transpose a Matrix
Python datetime
Python Program to Trim Whitespace From a String
Python map()
Python Variables, Constants and Literals
Python Numbers, Type Conversion and Mathematics
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python Program to Extract Extension From the File Name
Python Program to Sort Words in Alphabetic Order
Python Sets
Deep Learning with Python - Francois Chollet
Python vars()
Python Dictionary keys()
Python Program to Randomly Select an Element From the List
Python Set symmetric_difference()
Python Program to Differentiate Between del, remove, and pop on a List
Python Program to Print all Prime Numbers in an Interval
Python String lower()
Python for Programmers with introductory AI case studies - Paul Deitel & Harvey Deitel
Python String strip()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Keywords and Identifiers
Python Directory and Files Management
Python Inheritance
Python Program to Remove Duplicate Element From a List
Python reversed()
Python String rjust()
Python Closures
Python String count()
Python Set clear()