Expression and Statement


 Expression

        An expression is a combination of symbols that evaluates to a value. An expression is a combination of variables, operators, values, sub-expressions and a reserve keyword. Whenever we type an expression in the command line, the interpreter evaluates it and produces the result. expressions that evaluate to a numeric type are called arithmetic expressions. A sub expression is any expression that is part of a larger expression. Sub expression are denoted by the use of parentheses.

Example :  4+(3*k)

  An expression can also consist of a single literal or variable. Thus 4,3 and k are each expression. This expression has two sub-expression, 4 and (3*k). Sub-expression (3*k) itself has two sub-expression, 3 and k.

Boolean Expression

  A boolean expression may have only one of the two values : True or False.

Example :  5==5 
    
                True       # Output
  
In the given example comparison operator (==) is used which compares two operands and prints true if they are equal otherwise print false.


Statement

   Instructions that a Python interpreter can execute are called statements.

Assignment statement

   Assignment statements are used to create new variables, assign values, and change values. Assignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects. An assignment statement evaluates the expression list (that can be a single expression or a comma separated list) and assigns the resulting value to each of the target lists, from left to right.

Syntax of assignment statement :

LHS<=>RHS

Variable= Expression

Example :   A=2+3

No comments:

Post a Comment