I'm making a calculator in python 3 and I'm wondering if there is an option that can tell if the input the user gave is not a float. For example if the user wrote a word instead of a float the code will recognize it and print out something like: if num1 != float:     print(&quot;You Need To Enter A Number&quot;)
8128
What is the best possible way to check if a string can be represented as a number in Python?   The function I currently have right now is:  def is_number(s):     try:         float(s)         return True     except ValueError:         return False   Which, not only is ugly and slow, seems clunky. However I haven't found a better method because calling float in the main function is even worse.
60449
I see that within MySQL there are Cast() and Convert() functions to create integers from values, but is there any way to check to see if a value is an integer?  Something like is_int() in PHP is what I am looking for.
2266
In follow up to , it appears that some numbers cannot be represented by floating point at all, and instead are approximated.  How are floating point numbers stored?  Is there a common standard for the different sizes?  What kind of gotchas do I need to watch out for if I use floating point?  Are they cross-language compatible (ie, what conversions do I need to deal with to send a floating point number from a python program to a C program over TCP/IP)?
111701
I'm messing around with some C code using floats, and I'm getting 1.#INF00, -1.#IND00 and -1.#IND when I try to print floats in the screen. What does those values mean?  I believe that 1.#INF00 means positive infinity, but what about -1.#IND00 and -1.#IND? I also saw sometimes this value: 1.$NaN which is Not a Number, but what causes those strange values and how can those help me with debugging?  I'm using  which I believe uses  representation for float point numbers.  Can someone list all those invalid values and what they mean?
4398
What is the best way to check whether a given object is of a given type? How about checking whether the object inherits from a given type?  Let's say I have an object o. How do I check whether it's a str?
42087
Writing a python script and it needs to find out what language a block of code is written in. I could easily write this myself, but I'd like to know if a solution already exists.  Pygments is insufficient and unreliable.
10027
What would be the most efficient way to compare two double or two float values?  Simply doing this is not correct:  bool CompareDoubles1 (double A, double B) {    return A == B; }   But something like:  bool CompareDoubles2 (double A, double B)  {    diff = A - B;    return (diff &lt; EPSILON) &amp;&amp; (-diff &lt; EPSILON); }   Seems to waste processing.  Does anyone know a smarter float comparer?
11789
I'd like to convert a float to a whole number in JavaScript. Actually, I'd like to know how to do BOTH of the standard conversions: by truncating and by rounding. And efficiently, not via converting to a string and parsing.
41282
Here's my code:  x = 1.0 y = 100000.0     print x/y   My quotient displays as 1.00000e-05.  Is there any way to suppress scientific notation and make it display as 0.00001? I'm going to use the result as a string.
37488
This works just fine:      protected void txtTest_Load(object sender, EventArgs e)     {         if (sender is TextBox) {...}      }   Is there a way to check if sender is NOT a TextBox, some kind of an equivalent of != for "is"?  Please, don't suggest moving the logic to ELSE{} :)
73742
What is the best way to handle large numeric inputs in C++ (for example 10^100)?   For algorithms I usually switch over to ruby and I sometimes use strings.  Any other good methods?
17203
I need to know if a variable in Python is a string or a dict.  Is there anything wrong with the following code?  if type(x) == type(str()):     do_something_with_a_string(x) elif type(x) == type(dict()):     do_somethting_with_a_dict(x) else:     raise ValueError   Update: I accepted avisser's answer (though I will change my mind if someone explains why isinstance is preferred over type(x) is).  But thanks to nakedfanatic for reminding me that it's often cleaner to use a dict (as a case statement) than an if/elif/else series.  Let me elaborate on my use case.  If a variable is a string, I need to put it in a list.  If it's a dict, I need a list of the unique values.  Here's what I came up with:  def value_list(x):     cases = {str: lambda t: [t],              dict: lambda t: list(set(t.values()))}     try:         return cases[type(x)](x)     except KeyError:         return None   If isinstance is preferred, how would you write this value_list() function?
2201
I want a to be rounded to 13.95.  &gt;&gt;&gt; a 13.949999999999999 &gt;&gt;&gt; round(a, 2) 13.949999999999999   The  function does not work the way I expected.
9452
In Python, how can I parse a numeric string like "545.2222" to its corresponding float value, 545.2222? Or parse the string "31" to an integer, 31?  I just want to know how to parse a float str to a float, and (separately) an int str to an int.
12905
How do you get the  of two variables in Python?  For example, I have two variables that I expect to be strings. I want to test that only one of them contains a True value (is not None or the empty string):  str1 = raw_input("Enter string one:") str2 = raw_input("Enter string two:") if logical_xor(str1, str2):     print "ok" else:     print "bad"   The ^ operator seems to be bitwise, and not defined on all objects:  &gt;&gt;&gt; 1 ^ 1 0 &gt;&gt;&gt; 2 ^ 1 3 &gt;&gt;&gt; "abc" ^ "" Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: unsupported operand type(s) for ^: 'str' and 'str'
32263
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this?  I've read that in some languages the result can be machine-dependent, but I'm not sure though.
715
I would like to format a price in JavaScript. I'd like a function which takes a float as an argument and returns a string formatted like this: &quot;$ 2,500.00&quot;  What's the best way to do this?