close

[Solved] TypeError: ‘<' not supported between instances of 'str' and 'int'

Today We are Going To Solve TypeError: ‘<‘ not supported between instances of ‘str’ and ‘int’ in Python. Here we will Discuss All Possible Solutions and How this error Occurs So let’s get started with this Article.

How to Fix TypeError: ‘<‘ not supported between instances of ‘str’ and ‘int’ Error?

  1. How to Fix TypeError: ‘<' not supported between instances of 'str' and 'int' Error?

    To Fix TypeError: ‘<' not supported between instances of 'str' and 'int' Error just Cast an input string to an int. You can solve this error very easily. To solve it you have to cast that input string to an int. So here you can see this by giving the below example. You have to just change var1 = input('How are you') to var1 = int(input('How are you'))

  2. TypeError: ‘<' not supported between instances of 'str' and 'int'

    To Fix TypeError: ‘<' not supported between instances of 'str' and 'int' Error just use try catch. You can easily convert a string to an int by just using try catch. So try this just like given in the below example: try: input_var = int(user_input) except ValueError as err: pass

Solution 1 : Cast an input string to an int

You can solve this error very easily. To solve it you have to cast that input string to an int. So here you can see this by giving the below example. You have to just change

var1 = input('How are you')

to

var1 = int(input('How are you'))

Solution 2 : use try catch

You can easily convert a string to an int by just using try catch. So try this just like given in the below example:

try:
  input_var = int(user_input)
except ValueError as err:
  pass 

Conclusion

So these were all possible solutions to this error. I hope your error has been solved by this article. In the comments, tell us which solution worked? If you liked our article, please share it on your social media and comment on your suggestions. Thank you.

Also Read This Solutions

Leave a Comment