What is the difference between statement and expression?

Asked 1 years ago, Updated 1 years ago, 38 views

What is the difference between Statement and Expression?

[Is there a way to execute the stored Python code in the form of a string?] I saw a comment here.

I know the expression is in a smaller range

I'm inquiring because I don't know exactly how the statement and expression are different.

python expression

2022-09-22 14:13

1 Answers

expression includes only identifier, literal, and operator and is later expressed as a "value".

Here, the operator includes arithmetic (+, -, /, etc.), boolean (and, or not), () (function call), [] (subscription), etc.

3 + 5
map(lambda x: x*x, range(10))
yield 7

You can think of a statement as a more comprehensive "line."

Because expression alone can make a line, expression is also included in the statement, so it is also called an expiration statement.

print 42
if x: do_y()
return
a = 7


2022-09-22 14:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.