Expression and Statement:
- Expression: An expression is a combination of values, variables, operators, and function calls that evaluates to a single value. It can be as simple as a variable or a complex combination of multiple operators and operands. Examples of expressions:
- 5 + 3 (evaluates to 8)
- x * 2 (evaluates to the value of x multiplied by 2)
- sqrt(9) (evaluates to the square root of 9 using the sqrt function from the math module)
- Statement: A statement is a complete line of code that performs an action. It is a unit of execution and can include expressions. Statements are typically used to control the flow of a program, define variables, perform assignments, or call functions. Examples of statements:
- x = 5 (assigns the value 5 to the variable x)
- print(“Hello, world!”) (prints the text “Hello, world!” to the console)
- if x > 10: print(“x is greater than 10”) (checks if x is greater than 10 and executes the print statement if true)