Python Learning Series · @onlysamarrr · Day 3 / 30
Day 3 teaches input() and type casting. input() always returns text, even if the user types a number, so int() or float() must be used before doing maths with it.
Phase: Beginner · Reels: 11/450 – 15/450
Day 3 teaches input() and type casting. input() always returns text, even if the user types a number, so int() or float() must be used before doing maths with it.
age_text = "21"
print(age_text, type(age_text))
age = int(age_text)
print(age, type(age))
print(age + 1)
print(float("3.5"), str(10), bool(""))
21 <class 'str'> 21 <class 'int'> 22 3.5 10 False
Every form, calculator and signup page reads input as text first and converts it before calculating.
Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.
Q1. What does input() always return?
Q2. What is int("21") + 1?
Q3. What is float("3.5")?
| 11/450 | Concept | input() se user se data lo |
| 12/450 | Live demo | int(input()) live demo |
| 13/450 | Common mistake | input hamesha string deta hai |
| 14/450 | Quiz | Quiz: age calculator |
| 15/450 | Interview / real life | Interview: type casting kya hai |