Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: Python Programming. 3 Comments on Expression Evaluation in Python Programming
3
(3)

This article provides a overview of expression evaluation in Python programming language along with easy to understand examples.

 

Introduction to Expression Evaluation

 

A Python program contains one or more statements. A statement contains zero or more expressions. Python executes a statement by evaluating its expressions to values one by one. Python evaluates an expression by evaluating the sub-expressions and substituting their values.

 

Literal Expressions

 

A literal expression evaluates to the value it represents. Following are some examples of literal expressions:


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


 

10 => 10
‘Welcome to Python’ => ‘Welcome to Python’
7.89 => 7.89
True => True

 

Binary Expressions

 

A binary expression consists of a binary operator applied to two operand expressions. Examples:

 

2*6 => 12
8-6 => 2
8==8 => True
1000 > 100 => True
‘hello’ + ‘world’ => ‘helloworld’

 

Unary Expressions

 

An unary expression contains one operator and single operand. Examples:

 

-(5/5) => -1
-(3*4) => -12
-(2**4) => -16
-10 => -10

 

Compound Expressions

 

In a binary or unary expression, if an operand itself is an expression, such expression is known as a compound expression. Examples:

 

3 * 2 + 1 => 7
2 + 6 * 2 => 14
(2 + 6) * 2 => 16

 

Variable Access Expressions

 

A variable access expressions allows us to access the value of a variable. Examples:

 

>>>x = 10
>>>(x + 2) * 4
48
>>>x
10

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

3 Comments

You can follow any responses to this entry through the RSS 2.0 feed.

Content of the page is good, but it is less.
Provide more content to understand the topic briefly.
Thank you

    Hi Dhaval,

    I am rewriting the entire Python tutorial. But due to time constraints, I don’t know when it will be completed.

    Better to write example programs also

Leave a Reply

Your email address will not be published. Required fields are marked *