Python summary: operators

>>> “hello” == “hello” True

Where == is the operator and the two strings the operands.

It also is possible use the same operator in the same line, and/or other ones:

>>> "hello" == "hello" == "hello"
True
>>> "hello" == "hell" + "o"
True
>>> 2 == 1 + 1
True

 

The operator categories are:

  • Arithmetic
  • Comparison
  • Assignment
  • Logical
  • Bitwise
  • Membership
  • Identity

You will find everything on this page schematic way.

 

Finally, you must know operator functions exist (you will find them in the official documentation). For example:

>>> total = 2 + 3
>>> total
5
>>> import operator
>>> num1 = 2
>>> num2 = 3
>>> total = operator.add(num1, num2)
>>> total
5

 


More information:

Imprimir

Sé el primero en comentar

    Deja un comentario