Python input() Function Last Updated : 02 Jul, 2024 Comments Improve Suggest changes Like Article Like Report Python input() function is used to take user input. By default, it returns the user input in form of a string.input() Function Syntax: input(prompt)prompt [optional]: any string value to display as input messageEx: input("What is your name? ")Returns: Return a string value as input by the user.By default input() function helps in taking user input as string.If any user wants to take input as int or float, we just need to typecast it.Refer to all datatypes and examples from here.Python input() Function Example Python # Taking input as string color = input("What color is rose?: ") print(color) # Taking input as int # Typecasting to int n = int(input("How many roses?: ")) print(n) # Taking input as float # Typecasting to float price = float(input("Price of each rose?: ")) print(price) Output:What color is rose?: redredHow many roses?: 1010Price of each rose?: 15.5015.5Example 1: Taking the Name and Age of the user as input and printing itBy default, input returns a string. So the name and age will be stored as strings. Python # Taking name of the user as input # and storing it name variable name = input("Please Enter Your Name: ") # taking age of the user as input and # storing in into variable age age = input("Please Enter Your Age: ") print("Name & Age: ", name, age) Output:Please Enter Your Name: RohitPlease Enter Your Age: 16Name & Age: Rohit 16 Example 2: Taking two integers from users and adding them.In this example, we will be looking at how to take integer input from users. To take integer input we will be using int() along with Python input() Python # Taking number 1 from user as int num1 = int(input("Please Enter First Number: ")) # Taking number 2 from user as int num2 = int(input("Please Enter Second Number: ")) # adding num1 and num2 and storing them in # variable addition addition = num1 + num2 # printing print("The sum of the two given numbers is {} ".format(addition)) Output:Similarly, we can use float() to take two float numbers. Let's see one more example of how to take lists as inputExample 3: Taking Two lists as input and appending themTaking user input as a string and splitting on each character using list() to convert into list of characters. Python # Taking list1 input from user as list list1 = list(input("Please Enter Elements of list1: ")) # Taking list2 input from user as list list2 = list(input("Please Enter Elements of list2: ")) # appending list2 into list1 using .append function for i in list2: list1.append(i) # printing list1 print(list1) Output: Comment More infoAdvertise with us Next Article Taking input from console in Python bistpratham Follow Improve Article Tags : Python Python-Functions Practice Tags : pythonpython-functions Similar Reads Python Tutorial | Learn Python Programming Language Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio 10 min read Input and Output in Python Understanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython input() function is 8 min read Python basic I/O TechniquesTaking input in Python Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. While Python provides us with two inbuilt functions to read the input from the keyboard. input () 3 min read Python input() Function Python input() function is used to take user input. By default, it returns the user input in form of a string.input() Function Syntax: input(prompt)prompt [optional]: any string value to display as input messageEx: input("What is your name? ")Returns: Return a string value as input by the user.By de 4 min read Taking input from console in Python What is Console in Python? Console (also called Shell) is basically a command line interpreter that takes input from the user i.e one command at a time and interprets it. If it is error free then it runs the command and gives required output otherwise shows the error message. A Python Console looks 2 min read Python - Print Output using print() function Python print() function prints the message to the screen or any other standard output device. In this article, we will cover about print() function in Python as well as it's various operations.Python# print() function example print("GeeksforGeeks") a = [1, 2, 'gfg'] print(a) print() Function Syntax 4 min read Python - Output Formatting In Python, output formatting refers to the way data is presented when printed or logged. Proper formatting makes information more understandable and actionable. Python provides several ways to format strings effectively, ranging from old-style formatting to the newer f-string approach.Formatting Out 5 min read Python3 I/ODifferent Input and Output Techniques in Python3 An article describing basic Input and output techniques that we use while coding in python. Input Techniques 1. Taking input using input() function -> this function by default takes string as input. Example: Python3 #For string str = input() # For integers n = int(input()) # For floating or deci 3 min read Like