Page 478 - ComputerScience_Class_11
P. 478
12.3 EXPRESSION
An expression in Python is a combination of values (constants), variables, operators and sometimes function calls that
Python evaluates to produce a single result. In simple terms, an expression is anything that gives a value when it is
executed.
Expressions can perform calculations, compare values or even call functions, but their main purpose is to return a
result. The result of an expression can be a number, string, Boolean value (True/False) or any other data type.
For example,
1. 10 + 2 (evaluates to 12)
2. "Hello " + "World" (evaluates to "Hello World")
Program 11: To demonstrate different types of expressions in Python.
Program 11.py
File Edit Format Run Options Window Help
# Arithmetic expression
result1 = 8 + 2
print("Arithmetic Expression:", result1)
# Relational expression
result2 = 15 > 10
print("Relational Expression:", result2)
# Logical expression
result3 = (5 > 3) and (2 < 4)
print("Logical Expression:", result3)
# String expression
result4 = "Good" + " Morning"
print("String Expression:", result4)
# Membership expression
result5 = 3 in [1, 2, 3]
print("Membership Expression:", result5)
Output
Arithmetic Expression: 10
Relational Expression: True
Logical Expression: True
String Expression: Good Morning
Membership Expression: True
12.4 STATEMENT
A statement is a command or instruction written in a Python program that tells the computer to do something. It may
create a variable, display output, control program flow or perform any action. Statements do not necessarily return a
value; instead, they execute a task.
Unlike an expression, which only produces a value, a statement performs an operation or controls the flow of
the program.
476 Touchpad Computer Science (Ver. 3.0)-XI

