GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Articles
  • C#
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass

This view

  • Original page
  • New address

GeezerVison is showing www.tutorialsteacher.com — Python input() Method (With Examples)

Python input() Method

The input() method reads the user's input and returns it as a string.

input() Syntax:

input(prompt)

Parameters:

prompt: (Optional) A string, representing the default message before taking input.

Return Value:

A string.

The following example takes the user input using the input() method.

Example: Take User Input
>>> user_input = input() How are you? >>> user_input 'How are you?'

Above, the input() function takes the user's input in the next single line, so whatever user writes in a signle line would be assign to to a variable user_input. So, the value of a user_input would be whatever user has typed.

The following example demonstrets how to use the optional prompt parameter.

Example: Input with Prompt
>>> name = input('Enter Your Name: ') Enter Your Name: Steve >>> name 'Steve'

In the above example, the input('Enter Your Name: ') function with prompt string 'Enter Your Name: '. So, in the next line it will display a prompt first, asking user what to do. User can then enter the name after the prompt string in the same line and that would be assign to the name variable.

The input() function converts all the user input to a string even if that's the number.

Example: Input with Prompt
>>> age = input('Enter Your Age: ') Enter Your Name: 25 >>> age '25' >>> type(age) <class 'str'>

User can enter Unicode characters as well, as shown below.

Example: input() with Unicode Chars
>>> uc = input("Enter Unicode Char: ") Enter Unicode Char: åê >>> uc åê
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.