0

Pls What's the code to get what variable type a result is and how do I use it in conditional statements like 'if'?

Let's say for example I wrote a program for a quadratic equation calculator and I need to find out what type of variable my discriminant is (e.g integer, float or complex) and output the result to the user. how do I do that?

7th Dec 2016, 1:00 PM
Ade-onojobi Oluwadewalade
Ade-onojobi Oluwadewalade - avatar
2 Respuestas
+ 1
Just use type(myVar), which return the type of the variable and check the type using 'is' in the if statement. if(type(myVar) is float)
7th Dec 2016, 1:23 PM
Gleb Golov
Gleb Golov - avatar
+ 1
1) a= "string" type(a) ->>> output is string 2) a=12 type(a) ->> output is int 3)a=12.0 type(a)->>> output is float for example you want to make an integer so int(a) making an integer a variable a 4)a=[] type(a) ..->>> output is list etc.
8th Dec 2016, 2:13 AM
Murat Ahmedovich
Murat Ahmedovich - avatar