はじめに
移植やってます
None (Python)
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(a[2:])
print(a[2:-1])
print(a[2:None])
# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8]
# [2, 3, 4, 5, 6, 7, 8, 9]
へぇー、:None
だと末尾まで行くんだ。
nil (Ruby)
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
p a[2..]
p a[2...]
p a[2..-1]
p a[2...-1]
p a[2..nil]
p a[2...nil]
# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8]
# [2, 3, 4, 5, 6, 7, 8, 9]
# [2, 3, 4, 5, 6, 7, 8, 9]
-1
とは異なり、..nil
も...nil
も同じ動作となります。
メモ
- Python の None を学習した
- 道のりは遠そう