Python Operators:
A Python Operator is a symbol that is used to perform operations on variables and values.
For EXAMPLE:
10+20
30
Here,
- + is the operator that performs the addition.
- 10 and 20 are the operands.
- 30 is the output.
Python programming language divides the Operators into the following groups:
3.Comparison Operator
A comparison operator is used to comparing to values. The Comparison operators are described in the following table:
4.Logical Operator
Logical operators are used to combining conditional statements. The Logical operators are described in the following table:
5.Identity Operator
Identity operators are used to comparing the objects, not when they are equal, but when they are actually the same object, with the same memory location. The Identity operators are described in the following table:
6.Membership Operator
Membership operators are used to testing when a sequence is presented in the object. The Membership operators are described in the following table:
7.Bitwise Operator
Bitwise operators are used to comparing binary numbers. The Bitwise operators are described in the following table:
Python Comments:
Python comments can be used to explain Python code, make the code more readable, prevent execution when testing code. A good programmer must use the comments because in the future anyone wants to modify the code as well as implement the new module; then, it can be done easily.
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- Identity Operators
- Membership Operators
- Bitwise Operators
1.Arithmetic Operators
The basic Arithmetic Operators are addition, subtraction, multiplication, and division. Arithmetic is performed according to an order of operation.
Operators
|
Meanings
|
+
|
Addition
|
-
|
Subtraction
|
*
|
Multiplication
|
/
|
Divide
|
%
|
Modulus
|
//
|
Floor Division
|
**
|
Exponent
|
2.Assignment Operators
Assignment operators are used to assigning value to variables. The assignment operators are described in the following table:
Operators
|
Meanings
|
=
|
Assign the value of the right expression to
the left operand.
|
+=
|
Increases the value. For example: if a=10,
b=20=>a+=b will be equal to a=a+b, therefore, a=30.
|
-=
|
Decreases the value. For example: if a=10,
b=20>a-=b will be equal to a=a-b, therefore, a=10.
|
*=
|
Multiplies the value. For example: if a=10,
b=20=>a*=b will be equal to a=a*b, therefore, a=200.
|
%=
|
Divides the value. For example: if a=20,
b=10=>a % =b will be equal to a=a%b, therefore, a=0.
|
**==
|
a**=b will be equal to a=a**b, for example,
if a=4, b2, a**=b will assign 4**2=16 to a.
|
//=
|
A//=b will be equal to a=a//b, for example,
if a=4, b=3, a//=b will assign 4//3 = 1 to a.
|
3.Comparison Operator
A comparison operator is used to comparing to values. The Comparison operators are described in the following table:
Operators
|
Meaning
|
= =
|
equal
|
!=
|
not equal
|
>
|
greater than
|
<
|
less than
|
>=
|
greater than or equal to
|
<=
|
less than or equal to
|
4.Logical Operator
Logical operators are used to combining conditional statements. The Logical operators are described in the following table:
Operators
|
Meanings
|
and
|
returns true when both statements are true
|
or
|
returns true when one of the statement is
true
|
not
|
reverse the result, returns false when the
result is true
|
5.Identity Operator
Identity operators are used to comparing the objects, not when they are equal, but when they are actually the same object, with the same memory location. The Identity operators are described in the following table:
Operators
|
Meanings
|
is
|
returns true when both variables are the
same object
|
is not
|
returns true when both variables are not the
same object
|
6.Membership Operator
Membership operators are used to testing when a sequence is presented in the object. The Membership operators are described in the following table:
Operators
|
Meaning
|
in
|
returns true when a sequence with the specified
value is present in the object
|
not in
|
returns true when a sequence with not
the specified value is not present in the object
|
7.Bitwise Operator
Bitwise operators are used to comparing binary numbers. The Bitwise operators are described in the following table:
Operators
|
Meanings
|
&
|
bitwise AND
|
|
|
bitwise OR
|
^
|
XOR
|
~
|
bitwise NOT
|
<<
|
shift left
|
>>
|
shift right
|
Python Comments:
Python comments can be used to explain Python code, make the code more readable, prevent execution when testing code. A good programmer must use the comments because in the future anyone wants to modify the code as well as implement the new module; then, it can be done easily.
Creating a Comment:
Example:
#This is a comment
print("Welcome to TechieMania!")
Output:
Welcome to TechieMania!
- Comments start with a #, and Python will ignore them.
Example:
#This is a comment
print("Welcome to TechieMania!")
Output:
Welcome to TechieMania!
- Comments can be placed at the end of a line, and Python will ignore the rest of the line.
Example:
print("Welcome to TechieMania!") #This is a comment
Output:
Welcome to TechieMania!
Multiline Comments:
Python does not really have a syntax for multi-line comments. To add a multi-line comment you could insert a # for each line.
Example:
#This is a comment
#Written in
#more than just one line
print("Welcome to TechieMania!")
Output:
Welcome to TechieMania!
Hope this article found you interesting and stay tuned for more updates.
Thank You.
~ Jinal Menpara
Greatπ€π€
ReplyDeleteThank you π
DeleteDoing great☺️
ReplyDeleteThank you ☺️π
DeleteWonderfull explaination
ReplyDeleteIt's really easy to understand
ReplyDeleteExcellent work ππ
ReplyDeleteππππ₯π₯✨✨
ReplyDelete