Page 124 - Computer Class 08
P. 124
Variables and Data Types
Variable
As the name implies, a variable is something which can be changed. A variable is a way of
referring to a memory location used by a computer program. A variable is a symbolic name
for this physical location. This memory location contains values like numbers, texts or more
complicated values.
Data Type
Data Type represents the kind of value and determines how the value can be used. All data
values in Python are encapsulated in relevant object classes. Everything in Python is an object
and every object has an identity, a type and a value. Like another object–oriented language
such as Java or C++, there are several data types which are built into Python.
Operators in Python
Operators are special symbols in Python that carry out arithmetic or logical compulsion. The
value that the operator operates on is called the operand.
For example :
>>> 2 + 3
5
Here, + is the operator that performs addition. 2 and 3 are the operand and 5 is the output
of the operation.
Arithmetic Operators
Arithmetic operators are used to perform mathematical operations like addition, subtraction,
multiplication, etc.
Look at the following table carefully :
Operator Meaning Example
+ Add two operands or unary plus.
X + Y
– Subtract right operand from the left or unary minus. X – Y
* Multiply two operands. X * Y
Divide left operand by the right one (always
/ results into float). X/Y
Modulus remainder of the division of left operand X % Y
% by the right. (remainder of X/Y)
Floor division: division that results into whole
// X/Y
number adjusted to the left in the number line.
** Exponent: left operand raised to the power of right. x**y (X to the power y)
Computer-8 124