Page 400 - Computer_Science_F5
P. 400
special meanings and are reserved Operators
for specific purposes within the Operators are special symbols that perform
language. operations on variables and values. While
many operators are shared between Chapter Six: Object oriented programming with Python
The following are examples of writing Python and Java in previous chapter Five,
FOR ONLINE READING ONLY
variable names:
(i) myname = “Buricheka” there are notable differences in logical,
ternary, increment/decrement, and some
(ii) my_name = “ Buricheka “ arithmetic operations. Understanding these
(iii) _my_name = “ Buricheka “ differences is crucial when transitioning
(iv) myName = “ Buricheka “ between these two languages. Table 6.1
(v) MYNAME = “ Buricheka “ shows the differences of perators as used
(vi) myname3 = “ Buricheka “ in Java and Python:
Table 6.1: Differences in operators between Java and Python
Category Operator Java Python
Logical operators AND && and
OR || or
NOT ! not
Ternary operator condition ? if_true : a if condition else b
if_false
Increment/decrement Increment ++ N/A
operators Decrement -- N/A
Exponentiation Math.pow(a, b) a ** b
Floor Division / (when both operands a // b
are integers)
Expressions in Python
An expression is a combination of variables, operators, and values that yields a
result value.
For examples,
x = 10
y = 5
result = x + y * 2 # Here the result is 20
By understanding variables, operators, and expressions, you can create more
complex and powerful programs in Python. These fundamental concepts are the
building blocks for writing efficient and effective python code.
391
Student’s Book Form Five
Computer Science Form 5.indd 391 23/07/2024 12:34

