Remember college days, participate in the school's programming contest, in which the problem is:Write a function that converts decimal into 16 binary.Looks very simple a problem, finally unexpectedly did not realize, think all feel ashamed ah, go back online a search, that is quite easy things; after five or six years, the work has been used in Java, recently learned Python, so suddenly think of this proble
All types in Python exist as objects.There is no char type in Python, only a string type, which makes it very inconvenient for us to convert the char type to integer, but Python already provides built-in functions for these transformations.In Python, in addition to Integer, the other binary can only be represented by a
In my impression, it is a very common problem to convert to one another, so in Python, naturally, the following code should be util.
This is an online search from a also can be a python conversion, verified to be used. Its implementation code is posted below:
#!/usr/bin/env python #-*-coding:utf-8-*-# 2/10/16 base Trans. wrote by Srcdog on 20th, April, 2009
Write a string that can judge the input is not a decimal type1, determine whether the number of decimal points is 1 count2, determine if the decimal right is an integer isdigit3, judging the left of the decimal point 1, the integer isdigit,2 If it is a negative integer, take the minus sign to the right, if it is an int
Recently, when writing code, found a problem, want to determine whether a string is a valid decimal, found that the string does not have a built-in method of judging decimals, and then wrote a judge whether the string is a decimal, you can determine the positive and negative decimals, the code is as follows:
12345678910111213141516
pre class="Prettyprint lang-py">def is_float(s): s = str(s
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.