Swipe
Python - Basic 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.
Basic Operators
Python language supports the following types of
operators.
Arithmetic Operators
Comparison (Relational) Operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
Types of Operator
Arithmetic 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; '÷')
Comparison 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.
equal to
not equal to
greater than
greater than or equal to
less than
less than or equal to.
> , < , >= , <= , === , and !==
Different programming languages use different
syntax to express these operators, but the meanings
are the same.
6 - Comparison 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.
Assignment operators
operators
+=
-=
*=
/=
%=
<<=
>>=
&=
‸=
|=
Assignment operators
Logical 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.
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.
Logical 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.
Bitwise 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
&
|
^
~
<<
>>
Bitwise Operators
Membership 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
Identity 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.
Python - Decision Making
Python - Functions
Stay Tuned with
Topics for next Post

Python basic operators

  • 1.
  • 2.
    Operators are theconstructs 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. Basic Operators
  • 3.
    Python language supportsthe following types of operators. Arithmetic Operators Comparison (Relational) Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators Identity Operators Types of Operator
  • 4.
    Arithmetic Operators The basicarithmetic 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; '÷')
  • 5.
    Comparison Operators Comparison operatorscompare 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.
  • 6.
    equal to not equalto greater than greater than or equal to less than less than or equal to. > , < , >= , <= , === , and !== Different programming languages use different syntax to express these operators, but the meanings are the same. 6 - Comparison Operators
  • 7.
    Assignment operators areused 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. Assignment operators
  • 8.
  • 9.
    Logical Operators A logicaloperator 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.
  • 10.
    Logical AND If boththe 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. Logical Operators
  • 11.
    A bitwise operatoris 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. Bitwise Operators
  • 12.
    A bitwise operatoris 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 & | ^ ~ << >> Bitwise Operators
  • 13.
    Membership Operators The membershipoperators 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
  • 14.
    Identity Operators The identityoperators 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.
  • 15.
    Python - DecisionMaking Python - Functions Stay Tuned with Topics for next Post