[PYTHON] I tried to find out if m is included in what is called a range type or range such as n..m and range (n, m).

In the comment section of this article, it was a story like whether n..m includes m, so I investigated and summarized it. It is represented by open intervals, closed intervals and [n, m), [n, m].

Since some languages are not used normally, please point out any mistakes.

Premise

n and m are natural numbers in the range that does not overflow, or 0 and n <m.

Results in various languages

Rust

n .. m //m is not included

It's a derivative of Rust's article, so for now, Rust. m is not included.

Python

range(n, m)

does not include m. However, random.randint (n, m) has some complications such as including m.

Java

The IntStream class has a Range function and a RangeClosed function.

JavaScript (ES2016 or later), 0 Start only

...Array(m).keys()

This is a special case, but m is not included.

Ruby

n..m #Including
n...m #Not included

Image that beginners have more points to learn first

Elixir

n..m #Including

Elixir range types include m. It's very similar to Ruby.

PHP

range(n, m)

Including m

Kotlin

n..m

Includes m.

Swift

n...m //Including
n..<m //Not included

Scala

Range(n, m, 1) // [n, m),Interval 1
n to m //Including m
n until m //does not include m

Summary

Even similar languages are treated differently and are very confusing.

I mainly wrote the languages I know, so there may be biases and omissions.

Postscript: Which is the mainstream is a classification that does not make much sense, so it was abolished.

Recommended Posts

I tried to find out if m is included in what is called a range type or range such as n..m and range (n, m).
I tried to find out what would happen if I converted NaN or INF to int
I tried to find out if ReDoS is possible with Python
I tried to find out the difference between A + = B and A = A + B in Python, so make a note
I tried to find out what I can do because slicing is convenient
I tried to explain what a Python generator is for as easily as possible.
What to do if you cat or tail a binary file and the terminal is garbled
I tried to find out in which language that software that I always take care of is written
How to input a character string in Python and output it as it is or in the opposite direction.
What to do if there is a decimal in python json .dumps
What to do if you can't find PDO in Laravel or CakePHP
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
[Python] I tried to get the type name as a string from the type function
I tried to implement what seems to be a Windows snipping tool in Python
How to use any or all to check if it is in a dictionary (Hash)