# 3 [python3] Various operators

Introduction

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.

1 Numeric operator

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

2 string operator

The string operators are as follows.

operator Example Explanation
+ "a" + "b" String"ab"become
* "ab" * c String"ab"Repeat c times

3 comparison operator

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

4 logical operators

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

5 compound assignment operator

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

in conclusion

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

# 3 [python3] Various operators
Various processing of Python
Nesting Python ternary operators
Delete various whitespace characters [Python]
Python
About various encodings of Python 3
Manipulate various databases with Python
About Python string comparison operators
Nesting ternary operators in python
kafka python
[Python] Chapter 04-06 Various data structures (creating dictionaries)
Python basics ⑤
python + lottery 6
Python Summary
Built-in python
Python comprehension
Python technique
Studying python
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Various scraping
Python service
python tips
[Road to intermediate Python] Use ternary operators
Python Application: Data Visualization Part 3: Various Graphs
python function ①
Python basics
Python memo
ufo-> python (3)
Python comprehension
Mosaic images in various shapes (Python, OpenCV)
install python
Python Singleton
Python basics ④
Python Memorandum 2
python memo
Python Jinja2
Python increment
atCoder 173 Python
[Python] function
[Python] Chapter 04-03 Various data structures (multidimensional list)
Python installation
[Python] Chapter 04-04 Various data structures (see list)
python tips
Try python
Python memo
Python iterative
Python2 + word2vec
Python functions
Python tutorial
python underscore
Python summary
Start python
[Python] Sort
Note: Python
Python basics ③
python log
Python basics
[Scraping] Python scraping
Python update (2.6-> 2.7)