Hey!
I’m learning Python and I’m right now on the chapter “Control Flow”. I’ve just learned that you can see what type of class a data have by for example write: print(type(is_true)) it will output: <class ‘bool’> if it’s a boolean.
I just tried to do the exact same thing but with a if Statement. The result of that: print(type(if)) was this error: File “script.py”, line 15
print(type(if))
^
SyntaxError: invalid syntax
So my question is why can’t I class the if Statement?
You are actually saying “Print the type of variable that the word or command “if” is” which will turn up as an error because if is not a variable, it is a built in body of code which indicates a statement or a condition.
There is actually no variable for you to assign what is returned of each if, so you can’t check its type. If you type Return True o Return False, it will return a boolean outcome but you are not assigning it to a variable, so there is nothing you can apply type to…
I just wanna add some information. There is special termin for such a part of any program language - operator. “if”, such as “for”, “while”, “class”, “break”, and so on - are all operators, means it’s a special word in language, which start some sort of “constraction” like control flow. Also this words are resrved by language, so you cannot create a variable with name “if” and with name of other operators.