Answers for "operator in python"

13

! operator python

#The (!) is the not operator in Python, (!=) means not equal to.
if 2!=10:
  print("2 isn't equal to 10.")
elif 2==10:
  print("2 is equal to 10.")
#Prints "2 isn't equal to 10." as 2 isn't equal to 10. Is it?

#Note that "=" is used for declarations (assign a value to a variable or change the value of one) while "==" is usually used for checking.
#Usually, "==" returns a boolean, but depends on the objects being checked if they're equal or not, that the result will be boolean.
#For example, some NumPy objects when checked will return values other than boolean (other than True or False).

#For example:

a = 10
print(a)

#will return the int 10
#Now,

print(a==10)

#will return a boolean, True as we have assigned the value of a as 10

#Another example (to make it easier and to avoid confusion) would be where

a = 10
b = 10

#and

print(a==b)

#will return a boolean, True as they're equal.
Posted by: Guest on September-05-2021
0

logical operators python

Python uses and and or conditionals.

i.e.

if foo == 'abc' and bar == 'bac' or zoo == '123':
  # do something
Posted by: Guest on October-06-2020
0

Operators in python

x = 5
y = 6

d = 12 % 5     # d is 2
z = x + y      # z is 11
w = x - y      # w is -1
q = 5 * 6      # q is 30
u = 10 / x     # u is 2.0
p = 10 * 2.0   # p is 20.0
t = x ** 3     # t is 125
c = 28 // y    # c is 5
Posted by: Guest on October-17-2021

Python Answers by Framework

Browse Popular Code Answers by Language