Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If is a function or an operator in Python

Tags:

python

If is a function or an operator in Python. Just I am curious about it. In my opinion, it is a function because it gives output and accomplishes commands. I know that it is statement.

like image 955
Teymur Avatar asked Jul 31 '26 07:07

Teymur


1 Answers

As seen in the Operator Precedence table, inline if-else (a if cond else b) is an operator.

The if starting a conditional block is, however, neither an operator nor a function because it is a statement, as described in Chapter 3 of the Python documentation.

like image 188
Altareos Avatar answered Aug 02 '26 21:08

Altareos