A statement is a unit of code. Two types of statements are print and assignment. In interactive mode interpreter execute the statement and display the result. In script mode includes sequence of statements.
Operators are special symbols, that represent computations. The values the operator is applied to are called operands.
Operators are + (Addition), - (Subtraction), *(Multiplication), / (Division), and ** (Exponentiation).
When both the operands are integers , then the result is round downs to zero. If either the operands is a floating point number , then the python perform the floating point division.
An Expression is a combination of values, variables and operators.
If more than one operator appears in an expression, the order of evaluation depends on the rules pf precedence.
- Parentheses have the highest precedence. eg. 2 * (3-1) is 4
- Exponentiation has the next higher precedence. eg. 2**1 + 1 is 3
- Multiplication and division have the same precedence. eg. 2*3-1 is 5
- Addition and subtraction have the next precedence. eg. 6+4/2 is 8. Operators with the same precedence are evaluated from left to right.
Strings are enclosed in single or double quotes. '+' operator used for concatenation.
>>> a+b # '+' is used for concatenation operation.
'*' operator is also work with string.
>>> a*3 # Disply the value of a in 3 times
Assume that we execute the following assignment statements:
width = 17 height = 12.0 delimiter = '.'
For each of the following expressions, write the value of the expression
- 1 + 2 * 5
- delimiter * 5
Use the Python interpreter to check your answers
>>> delimiter = '.'
>>> delimiter *5