You are on page 1of 11

Role of Assignment

Statement

1
EXPRESSION
• Expressions are pieces of text that represent a
computation.
• When an expression is evaluated the result is a
value.
• For example the text character '5' has the value
equal to the number five. Note that the text
character '5' is not the number five, it is only an
expression that represents the number five.
• 0b101 is an expression that uses the binary
representation for the number five.
2
Primitive Expression is an expression that
represents the resultant internal value that it
generates inside the interpreter. 10 is a
primitive expression 10 + 10 is not.

3
Numerical Data Types --
int, float
Data Types

None
Numeric
(int,float,complex,bool)
List
Tuple
Set
String
Dictionary
Range

4
Compound Expression
• An expression that is formed by combining
multiple expressions together. For
example 4 + len("abc") is a compound
expression formed from a primitive
expressions ('4') and a function call
expression (len("abc")) using the addition
operator.

5
Evaluation of Expressions in
Python
• Python is an Object Oriented Language.
Internally almost everything it deals with is
in terms of Objects.
• Primitive expressions that can be used to
represent data (5, 'a String') and functions
that can be called by giving Python
function call expressions to evaluate.
• Objects combine these together to form a
single unit.
6
Objects in Python consist of
the following three things:
• id: All objects that exist in Python at any given
time have unique ids.
• Data Value and its type: This is a value like 5
or 'a string'. The Object also stores the type of
the data value
• List of functions: A list of functions/operators
associated with the data value. So for example
the functions of addition, multiplication(+ , *) for
the data value 5.

7
Evaluation of Primitive
Expressions in Python
• Python evaluates a primitive expression by
making an object out of it. So for example,
when you give Python the expression:
• >>> 5
• to evaluate internally it makes an object
out of it.

8
• Python provides various functions to let us
see the various parts of an object:
– >>> print(5) #print the data value 5
– >>> type(5) #print the data type
– >>> id(5) #print the object id 24465656
– >>> print(dir(5)) #print the list of functions
['__abs__', '__add__', '__and__', '__class__',
'__cmp__', '__coerce__', '__delattr__',
'__div__', '__divmod__', ... .... 'conjugate',
'denominator', 'imag', 'numerator', 'real'] 9
Evaluation of Compound
Expressions in Python
• if we give Python the expression "4 + 5" to
evaluate, Python follows the following
steps in its evaluation.
– Convert the primitive expression 4 to an
object
– Convert the primitive expression 5 to an
object
– Adds the data value of both the objects
together (result is 9)
– Converts the resultant value to an object
10
VARIABLES

• A variable is a storage location in a


computer program. Each variable has a
name and holds a value.

11

You might also like