What is the definition of the word operator? (Python, another language)

Asked 2 years ago, Updated 2 years ago, 223 views

In Python, = is not an operator
It is said that
So what is the definition of the word operator?

I would appreciate it if you could tell me both Python and other languages.

python

2022-09-30 21:56

2 Answers

Generally speaking, the programming language distinguishes the expression; expression; expression from the statement where 1+1 is the expression and the if statement is the statement

.
 if x >y:
    x
else:
    y

Then, the statement can contain the expression and vice versa.What is the expression and what is the statement vary by programming language.

Then, the element that makes up the expression has the operator and 1+1 has the addition operator.

Based on this assumption, Python defines the operator as follows:

The following tokens are operators:

As you can see, = is not included in the list of operators where = is defined as assignment statement; substitute.

Of course, the definitions in other languages are different.For example, In the C++ language, = is the substitution operator.


2022-09-30 21:56

As far as I know, there should be no widely used formula definition for the term operator in Python.A little more limited operator for Python terminology analysis might have a definition, but that doesn't mean that substitute = should not be called an operator. The .

However, a common distinction is that Python substitution is statement but not expression.In other words, substitutions in Python do not return values.Specifically, writing a=(b=42) does not mean that b=42 returns any value, but it is an error.

In some programming languages, substitutions return values.For example, in C language, when evaluating b=42, not only b but 42 is replaced, but 42 is returned as a return value, so writing a=(b=42) also replaces a.In C language, substitution can also be considered an expression that returns some value.

To sum up, Python substitution = is sometimes referred to as a substitution operator for clarity, but it has a different nature than other operators such as + and == and does not return a value.Other programming languages may be designed to return values, but Python does not.


2022-09-30 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.