Title: Python - Basics Operations
1Python - Basic Operators
Swipe
2Basic Operators
Operators are the constructs which can
manipulate the value of operands. Consider the
expression 4 5 9. Here, 4 and 5 are called
operands and is called operator. Operators
perform mathematical, string, and logical
operations on values. Operands are expressions
on which operations are performed.
3Types of Operator
Python language supports the following types of
operators. Arithmetic Operators Comparison
(Relational) Operators Assignment
Operators Logical Operators Bitwise Operators
Membership Operators Identity Operators
4Arithmetic Operators
The basic arithmetic operations for real numbers
are addition, subtraction, multiplication, and
division. The basic arithmetic properties are
the commutative, associative, and distributive
properties. The four basic arithmetic operations
in Maths, for all real numbers, are Addition
(Finding the Sum '') Subtraction (Finding the
difference '-') Multiplication (Finding the
product '' ) Division (Finding the quotient
'')
5Comparison Operators
Comparison operators compare the contents in a
field to either the contents in another field or
a constant. They may be used alone or in
combination with other operators and functions
in both record expressions and target field
expressions.
66 - Comparison Operators
Different programming languages use different
syntax to express these operators, but the
meanings are the same. equal to not equal to
greater than greater than or equal to less
than less than or equal to. gt , lt , gt , lt ,
, and !
7Assignment operators
Assignment operators are used to assign value to
a variable. This operator first adds the current
value of the variable on left to the value on
the right and then assigns the result to the
variable on the left. Example (a b) can be
written as (a a b) If initially value stored
in a is 5.
8Assignment operators
operators - / ltlt gtgt ?
9Logical Operators
A logical operator is a symbol or word used to
connect two or more expressions such that the
value of the compound expression produced
depends only on that of the original expressions
and on the meaning of the operator. Common
logical operators include AND, OR, and
NOT. For example- a b returns true when
both a and b are true (i.e. non-zero). Logical
OR operator The '' operator returns true even
if one (or both) of the conditions under
consideration is satisfied. Otherwise it returns
false.
10Logical Operators
Logical AND If both the operands are true then
condition becomes true - (a and b) is
true. Logical If any of the two operands are
non-zero then condition becomes true - (a or b)
is true. Logical NOT Used to reverse the logical
state of its operand - Not(a and b) is false.
11Bitwise Operators
A bitwise operator is an operator used to perform
bitwise operations on bit patterns or binary
numerals that involve the manipulation of
individual bits. Bitwise operators are used in
Communication stacks where the individual bits
in the header attached to the data signify
important information.
12Bitwise Operators
A bitwise operator is an operator used to perform
bitwise operations on bit patterns or binary
numerals that involve the manipulation of
individual bits. Bitwise operators are used in
Communication stacks where the individual bits
in the header attached to the data signify
important information. Operators ltlt gtgt
13Membership Operators
The membership operators in Python are used to
test whether a value is found within a
sequence. For example, you can use the membership
operators to test for the presence of a
substring in a string. For example, 'Hello' in
'Hello world' returns True because the substring
Hello is present in the string Hello
world!. Operator in Returns True if a sequence
with the specified value is present in the
object - x in y not in Returns True if a
sequence with the specified value is not present
in the object - x not in y
14Identity Operators
- The identity operators in Python are used to
determine whether a value is of a certain class
or type. They are usually used to determine the
type of data a certain variable contains. - is
- This returns True if both variables are the same
object - x is y. - is not
- This returns True if both variables are not the
same object - x is not y.
15Topics for next Post
Python - Decision Making Python -
Functions Stay Tuned with