r/PythonLearning • • 17d ago

Help Request Need help understanding how != works

Hello, I'm working on learning the basics of try/except blocks. To do so, I'm intentionally raising errors. The question is: why is my TypeError occurring when I enter an integer? I checked the input type, and it shows as an integer, but the error is still raised. What am I missing here?

31 Upvotes

17 comments sorted by

View all comments

1

u/atarivcs 17d ago
carsAvailable = int(...)

If that assignment succeeds, carsAvailable is guaranteed to be an integer. Checking the type is redundant.

2

u/Vdpants 17d ago

also if you input a text value, it will convert into an int, which it can't, so it will give you an error before you even check if it's an int.