Categories: Python

Operator in python programming language

Operator in python programming language

Python programming language provides many types of operator for arithmetic calculations and operations.


Arithmetic operators

Arithmetic operators are used to perform mathematical calculations or operations.

Arithmetic
Example for arithmetic operators
program 1
Example

Comparison operators

Comparison operators are used to compare values. It either returns true or false values only according to the given condition.
Comparision
Example 1
Comparision example

Logical operators

The logical operator are used in conditional statements that are true or false. The logical operator in Python are AND or OR or NOT
There are three logical operators available in python
Logical
Example 1
AND operator
Logical examplw
Output
(‘a and a:’, True)
(‘a and b:’, False)
(‘b and b:’, False)
Example 2
OR operator
Output
a or a: True
a or b: True
b or b: False
Example 3
NOT operator
Output
not a: False
not b: True

Bitwise operators

Bitwise
Program 1
Output
value of x&y 18
value of x|y 63
value of x^y 45
value of ~y -19
value of x<<2 -19
value of x>>2 -19

 

Assignment operators

Assignment operators are used in python to assign values to the variable

Assignment
Program 1
Output
value of a=x+y : 42
value of a+=y : 52
value of a*=y : 520
value of a/=y : 52
value of a%=y : 2
value of a**=y : 1024
value of a**=y : 102

 

Similar post

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.