This article is written by a fledgling engineer who has been studying programming for about two months for the purpose of output. After biting ruby and js, I became interested in the trend python, so I started learning. This time I will write an article about various operators. This is a poor article, but I would appreciate it if you could point out any points that interest you! This article is based on the assumption that python3 and anaconda are installed on macOS.
This is a typical operator.
operator | Example | Explanation |
---|---|---|
+ | a + b | addition |
- | a - b | subtraction |
* | a * b | multiplication |
/ | a / b | division |
// | a // b | Division (rounded down to the nearest whole number) |
% | a % b | Division (remainder when a is divided by b) |
** | a ** b | Exponentiation |
The string operators are as follows.
operator | Example | Explanation |
---|---|---|
+ | "a" + "b" | String"ab"become |
* | "ab" * c | String"ab"Repeat c times |
This is a typical comparison operator.
operator | Example | Explanation |
---|---|---|
== | a == b | true when a and b are equal |
!= | a != b | true when a and b are different |
> | a > b | true when a is greater than b |
>= | a >= b | true when a is greater than or equal to b |
< | a < b | true when a is less than b |
<= | a <= b | true when a is less than or equal to b |
The logical operators are as follows.
operator | Example | Explanation |
---|---|---|
and | a and b | true when a and b |
or | a or b | true when a or b |
not | not a | false if a is true |
This is a typical compound assignment operator.
operator | Example | Explanation |
---|---|---|
+= | a += b | a = a + b |
-= | a -= b | a = a - b |
*= | a *= b | a = a*b |
/= | a /= b | a = a / b |
//= | a //= b | a = a / b |
%= | a %= b | a = a % b |
**= | a **= b | a = a ** b |
This is the end of this article. These operators are no different from the ruby I was learning before, so it was easy to understand. I think these operators are probably essential knowledge in development, so I want to understand them perfectly.
Previous article → https://qiita.com/shin12032123/items/543a25bd5777d6e18128 Next article → https://qiita.com/shin12032123/items/a8cc0d7612259683562e
Recommended Posts