Thanks to visit codestin.com
Credit goes to www.tutorialsteacher.com

Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • Python - Get Started
  • What is Python?
  • Where to use Python?
  • Python Version History
  • Install Python
  • Python - Shell/REPL
  • Python IDLE
  • Python Editors
  • Python Syntax
  • Python Keywords
  • Python Variables
  • Python Data Types
  • Number
  • String
  • List
  • Tuple
  • Set
  • Dictionary
  • Python Operators
  • Python Conditions - if, elif
  • Python While Loop
  • Python For Loop
  • User Defined Functions
  • Lambda Functions
  • Variable Scope
  • Python Modules
  • Module Attributes
  • Python Packages
  • Python PIP
  • __main__, __name__
  • Python Built-in Modules
  • OS Module
  • Sys Module
  • Math Module
  • Statistics Module
  • Collections Module
  • Random Module
  • Python Generator Function
  • Python List Comprehension
  • Python Recursion
  • Python Built-in Error Types
  • Python Exception Handling
  • Python Assert Statement
  • Define Class in Python
  • Inheritance in Python
  • Python Access Modifiers
  • Python Decorators
  • @property Decorator
  • @classmethod Decorator
  • @staticmethod Decorator
  • Python Dunder Methods
  • CRUD Operations in Python
  • Python Read, Write Files
  • Regex in Python
  • Create GUI using Tkinter
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

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 åê
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.