1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

はじめに

移植やってます。

__getitem__ (Python)

    def __getitem__(self, key):
        if isinstance(key, (int, float)):
        if isinstance(key, Sequence):
        if isinstance(key, slice):

__getitem__についての詳しい解説は、こちらの Pythonの getitem に与える引数やスライスについて調べてみた - Qiita にあります。

誰だっ、Pythonが初心者向けって言ったの!

どうする? (Ruby)

class Getitem
  def [](*args)
    if args.size > 1
      puts args.class
    else
      puts args[0].class
    end
  end
end

g = Getitem.new()
g[1, 2]
g[1..2]
g[1]
g['1']

# Array
# Range  
# Integer
# String

むしろこういうのは、Rubyの方が得意に思えます。

メモ

  • Python の __getitem__ を学習した
  • 道のりは遠そう
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?