Describes how Python determines whether a number is a positive decimal or integer.

Source: Internet
Author: User
This article mainly introduces Python to determine whether it is a positive decimal and positive integer instances of the relevant data, here provides examples, examples of annotations are clear, the need for friends can refer to the following

Python determines whether an instance of a positive decimal and a positive integer

Implementation code:

def check_float (string):  #支付时, the amount entered may be a decimal or an integer  s = str (string)  if S.count ('. ') = = 1: # Determine the number of decimal points    SL = S.split ('. ') # Splits by decimal point left    = sl[0] # before the decimal point right    = sl[1] # After the decimal point    if Left.startswith ('-') and Left.count (' -') = = 1 and Right.isdigit ():      lleft = Left.split ('-') [1] # Follow-split, then take the number after the minus sign      if Lleft.isdigit ():        return False    elif Left.isdigit () and Right.isdigit ():      # Determines whether a positive decimal      return True  elif s.isdigit ():    s = Int (s)    if s! = 0:      return True  return False

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.