Specifying the range of ruby and python arrays

・ For ruby

tmp.rb


array = [1,2,3,4,5]
array[0, 2] # => [1, 2]

array[2, 3] # => [3, 4, 5]
array[2, 1] # => [3]

array[2, 2]  #=> [3, 4]
array[2, 0] # => []

・ For python

tmp.py


array = [1,2,3,4,5]

print(array[0:2]) # => [1,2]

print(array[2:3]) # => [3]

print(array[2:2]) # => []

In case of ruby, specify the number of elements with the second argument In case of python, specify the element number with the second argument

Recommended Posts

Specifying the range of ruby and python arrays
Visualize the range of interpolation and extrapolation with python
The story of Python and the story of NaN
I compared the speed of Hash with Topaz, Ruby and Python
Correspondence summary of array operation of ruby and python
Summary of the differences between PHP and Python
The answer of "1/2" is different between python2 and 3
Ruby, Python and map
the zen of Python
Compare the speed of Python append and map
Python and Ruby split
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
About shallow and deep copies of Python / Ruby
Comparison of Python and Ruby (Environment / Grammar / Literal)
I compared the speed of regular expressions in Ruby, Python, and Perl (2013 version)
Divides the character string by the specified number of characters. In Ruby and Python.
The story of Python without increment and decrement operators.
The process of installing Atom and getting Python running
Python --Explanation and usage summary of the top 24 packages
Difference between Ruby and Python in terms of variables
Referencing and changing the upper bound of Python recursion
I checked out the versions of Blender and Python
Comparison of CoffeeScript with JavaScript, Python and Ruby grammar
Version control of Node, Ruby and Python with anyenv
Towards the retirement of Python2
Python on Ruby and angry Ruby on Python
About the ease of Python
Python and ruby slice memo
python> Handling of 2D arrays
Ruby and Python syntax ~ branch ~
About the features of Python
Source installation and installation of Python
The Power of Pandas: Python
The timing when the value of the default argument is evaluated is different between Ruby and Python.
[Python] Heron's formula functionalization and calculation of the maximum area
[python] plot the values ​​before and after the conversion of yeojohnson conversion
[Python3] Call by dynamically specifying the keyword argument of the function
Summary of Hash (Dictionary) operation support for Ruby and Python
The process of making Python code object-oriented and improving it
The websocket of toio (nodejs) and python / websocket do not connect.
I want to know the features of Python and pip
[Tips] Problems and solutions in the development of python + kivy
Play with the password mechanism of GitHub Webhook and Python
Environment construction of python and opencv
Difference between Ruby and Python split
Installation of SciPy and matplotlib (Python)
[Python] The stumbling block of import
Scraping with Node, Ruby and Python
First Python 3 ~ The beginning of repetition ~
Existence from the viewpoint of Python
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
This and that of python properties
[Python] Understanding the potential_field_planning of Python Robotics
Review of the basics of Python (FizzBuzz)
Coexistence of Python2 and 3 with CircleCI (1.0)
About the basics list of Python basics
Summary of Python indexes and slices
Reputation of Python books and reference books
Learn the basics of Python ① Beginners