Python determines whether the instance is a positive decimal or a positive integer, and python decimal

Source: Internet
Author: User

Python determines whether the instance is a positive decimal or a positive integer, and python decimal

Python determines whether an instance is a positive decimal or a positive integer.

Implementation Code:

Def check_float (string): # The input amount may be decimal or integer s = str (string) if s. count ('. ') = 1: # determine the number of decimal places sl = s. split ('. ') # split by decimal point left = sl [0] # right Before decimal point = sl [1] # if left after decimal point. startswith ('-') and left. count ('-') = 1 and right. isdigit (): lleft = left. split ('-') [1] # split by-, and then take the number after the minus sign if lleft. isdigit (): return False elif left. isdigit () and right. isdigit (): # determines whether the return True elif s is a positive decimal. isdigit (): S = int (s) if s! = 0: return True return False

The above is a detailed explanation of whether python determines whether it is a positive decimal point or a positive integer. There are many articles related to python on this site. I hope you can search for them and thank you for reading them. I hope they can help you, thank you for your support!

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.