Python---typeerror: ' < ' not supported between instances of ' str ' and ' int ' __python

Source: Internet
Author: User

According to the year of birth that the user entered, judge and print whether the user is 00 or 00 ago

Birth = input (' Birth: ')
if birth <:
	print (' 00 ago ')
else:
	print (' 00 after ')


At this point if you enter 1988 directly, the error is as follows:

Traceback (most recent call last):
File "z.py", line 2, in <module>
If birth < 2000:
TypeError: ' < ' not supported between instances of ' str ' and ' int '
This is because input () returns a data type that is STR and cannot be compared directly to integers, you must first change the str to an integer, using the Int () method:

s = input (' Birth: ')
birth = Int (s)
if birth <:
	print (' 00 ago ')
else:
	print (' 00 after ')


For more IOS,Android, Python articles, click on:

Http://blog.csdn.net/jamiecheung


For more Java, Unity3d articles, please click:

http://blog.csdn.net/u010841622


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.