User Input in Python | Python Notes By Mr. BILRED - TechAmbitionX
User Input in Python — Talk to Your Code!
What is User Input?
User input means taking data from the user while the program is running.
In Python, we use the built-in input()
function.
Basic Example
name = input("What's your name? ")
print("Hello, " + name + "!")
Output:
What's your name? Mr. BILRED
Hello, Mr. BILRED!
Want Numbers? Convert Them
input()
always returns a string. If you want a number, convert it like this:
age = int(input("Enter your age: "))
print(age + 1)
You Can Use float()
too
gpa = float(input("Enter your GPA: "))
print("apki GPA times 2 is", gpa * 2)
Use Inputs in Real Programs
username = input("Username: ")
password = input("Password: ")
print(f"Logging in as {username}...")
🔐 Optional: Hide Sensitive Input
from getpass import getpass
password = getpass("Enter your password: ")
(You type the password, but it won’t show any characters on the screen — not even asterisks)
🔁 Quick Recap
Feature | Syntax | Type |
---|---|---|
Basic Input | input("Message") |
string |
Integer Input | int(input("...")) |
integer |
Float Input | float(input("...")) |
float |
Secure Input | getpass("...") |
string |
👀 Hidden Message
U2VsZiBPYnNlc3Npb24gSXMgQmV0dGVyIFRoYW4gRGVwcmVzc2VkIE9ic2Vzc2lvbiAtIEJpbGFsIEFobWFkIEtoYW4gQUtBIE1yLiBCSUxSRUQ=
Related Topics:
You Can Try Your Code Here
This post is for educational purposes only.
Comments
Post a Comment