⌨️ Taking Input

Last Updated: 13th August 2025


  • The input() function lets you take user input from the keyboard.
  • It always returns the input as a string by default, even if you type a number.
  • If you need numeric values, you must type cast them (we already learned type casting for int, float, etc.).

Hinglish Tip 🗣: input() se user se data lete hain, aur default me ye hamesha string deta hai.


Basic Syntax

variable_name = input("Your message here: ")

Here,

  • "Your message here" → message shown to the user (optional).
  • variable_name → where the input value will be stored.

Example:

  • Taking String Input:
    name = input("Enter your name: ")
    print("Hello, ", name)
    
  • Taking Numeric Input:
    age = int(input("Enter your age: "))
    print("Your age is: ", age)
    
  • Taking Float Input:
    height = float(input("Enter your height: "))
    print("Your height is: ", height)
    
  • Taking Multiple Inputs in One Line:
    a, b = input("Enter two numbers: ").split()
    print("First:", a)
    print("Second:", b)
    

    Hinglish Tip 🗣: split() se input ko alag-alag tod ke variables me store kar sakte hain.


💡 Quick Practice

  • Take your friend’s name as input and print "Hi, (name)".
  • Take an integer as input and print its square.
  • Take a float as input for temperature and print it.
  • Take two integers in one line (space-separated) and print them.
  • Take a complex number as input and print its type.