User Input in Python | Python Notes By Mr. BILRED - TechAmbitionX

User Input in Python — Learn input(), int(), float(), and getpass() | 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=

You Can Try Your Code Here

This post is for educational purposes only.

Comments

Popular posts from this blog

Bits, Bytes, Binary, and ASCII: The Fundamentals of Data Representation - Compiled By Bilal Ahmad Khan AKA Mr. BILRED - TechAmbitionX

C++ escape sequences with clear examples and outputs - Compiled By Bilal Ahmad Khan AKA Mr. BILRED

C++ Prog Lang In A Nutshell VOL #2 Compiled By Bilal Ahmad Khan AKA Mr. BILRED - TechAmbitonX