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?
2 odpowiedzi
+ 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)
+ 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.