Skip to content
Worked Examples · Example 5.15

Q.Example 5.15:
#function int() to convert string to integer
age = int( input("Enter your age:"))
Enter your age: 19
type(age)
<class 'int'>

Sikkim CbseNCERTSubjective· 2mImportance★★★★★est
53% · 26/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 →

Wrapping input() in int() converts the typed text to an integer immediately — age becomes the int 19, and type(age) confirms <class 'int'>.

The concept is explicit type conversion at the point of input. Example 5.14 showed that input() always yields a string; this example composes two functions — int( input(...) ) — so the string is converted the moment it arrives, and the variable holds a genuine number from the start.

#function int() to convert string to integer
>>> age = int(input("Enter your age: "))
Enter your age: 19
>>> type(age)
<class 'int'>

Order of evaluation (inside-out):

StepCallResult
1input("Enter your age: ")user types 19 → returns the string '19'
2int('19')converts → the integer 19
3age = 19age is bound to the int
4type(age)<class 'int'>

Now arithmetic works naturally:

>>> age + 1
20
``` …

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.