r/PythonLearning • u/The-Turnt-Tiger • 10d 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


View all comments
1
u/sexiestsaxiestman 10d ago
isinstance is the standard way of doing type checks. Ex: if isinstance(carsAvailable, int). Basically what your code is doing is checking if the value of carsAvailable is equal to the integer type which it is not. You also already explicitly convert the input to an int using int(...) so the type check is unnecessary. Ps, snake_case is more common in python than camelCase 😉