What are the basic operators in python?

Description

To see the basic operators in python3.

Arithmetic operator.

Operators:

+ , - , * , / , % , ** , //

Used to perform basic arithmetic like addition, subtraction, multiplication, division.

Comparison operator.

Operators:

== , != , > , < , <= , >=

These operators compare the values on either side of them and decide the relation among them.

These are also called as relational operators.

Assignment operator.

Operators:

= , += , -= , *= , /= , %=, //=

These operators used to assigns values from right side operands to left side operand.

Logical operator.

Operators:

and Logical AND, or Logical OR, not Logical NOT.

If both the operands are true then condition becomes true.

Membership operator.

Operators:

in , not in

Python membership operators test for membership in a sequence, such as strings, lists, or tuples.

#get input from user
num=int(input(“enter the number:”))

#using conditional operator
if num > 1:

#using membership operator
for i in range(2,num):

#using arithmetic and assignment operator
if (num % i== 0):
print(num,”is not a prime number”)

#using arithmetic operator
print(num+2)
break
else:
print(num,”is a prime number”)
print(num-2)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit