Skip to content
Worked Examples · Example 5.14

Q.Example 5.14:
fname = input("Enter your first name: ")
Enter your first name: Arnab
age = input("Enter your age: ")
Enter your age: 19
type(age)
<class 'str'>

Punjab PsebTextbookSubjective· 2mImportance★★★★★est
51% · 25/49 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Whatever the user types, input() delivers it as a string — the age typed as 19 is stored as '19', and type(age) confirms <class 'str'>.

The concept is the return type of input(): the function reads a line from the keyboard and returns it as a str, always. It does not inspect the text and guess that "19" should be a number — type conversion is the programmer's explicit job.

>>> fname = input("Enter your first name: ")
Enter your first name: Arnab
>>> age = input("Enter your age: ")
Enter your age: 19
>>> type(age)
<class 'str'>

Walking through:

  • input("Enter your first name: ") — displays the prompt, waits, returns the typed text; fname holds 'Arnab' (str — as expected for a name).
  • input("Enter your age: ") — the user types 19, but what age receives is the string '19': two characters, not the integer nineteen.
  • type(age) → <class 'str'> — the proof.

Why it matters — the string '19' cannot take part in arithmetic:

>>> age + 1
TypeError: can only concatenate str (not "int") to str
>>> age + '1'
'191'
``` …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.