Python Operators Flashcards
What are Comparison operators?
In Python, comparison operators are used to compare two values and return a boolean value, either True or False. Common comparison operators include:
• == (equal to) • != (not equal to) • > (greater than) • < (less than) • >= (greater than or equal to) • <= (less than or equal to)
What does == mean?
means check for equality
Examples
2 == 2 True
3 == 0 false
What does != mean?
Examples
2 != 2 False
2 != 1 True
Whats is this: %?
Modulus the maths out a remainder of something.
Example:
20 % 3 = 3
10 % 3 = 1
11 % 3 = 2
Waht is this: //?
Floor division
unlike normal division where the left operand is divided by the right, floor division divises that result into whole number, but adjusted to the left in the number line.
Example:
10/3 = 3.33333r
10//3 = 3
9/2 = 4.5
9//2 = 4
What is **?
Exponent
example:
3 ** 3 = 27
Write another way of: x = x + 1
x += 1