Programming Algorithms Lesson002
Programming Algorithms Lesson002
Introduction to Python
Variables in Python
What is a Variable?
A variable is like a labeled box that stores data. it is a named storage location in a computer's
memory that holds a value which can change (vary) during the execution of a program.
Name (Identifier) → Used to refer to the stored value (e.g., age, score, name).
Data Type → Defines the kind of data the variable can hold (e.g., integer, string, float).
age = 25
name = "Alice"
price = 19.99
Operators in Python
A. Arithmetic Operators
Example:
a = 10
b=3
sum = a + b
print(sum)
a = 13
b =2
multiplication = a* b
print (multiplication)
Comparison Operators
== a == b Equal to
!= a != b Not equal to
Example:
x, y = 5, 10
print(x == y)
print(x < y)
Logical Operators
They are fundamental for building blocks in programming that allows you to combine and
modify Boolean (true/false) values.
AND a and b will return True if only both operands are True
NOT not a Inverts the condition, returns the opposite Boolean value (True→False)
Example
age = 20
is_student = True
True
has_ticket = False
True
Simple if Statement
age = 18
if-else Statement
print("Adult")
else:
print("Minor")